b python2与python3中的print语句的格式没有变化

huuhanhyahoo1

New member
#Python #python2 #python3 #print ### python2 python3 中 in 语句 的 变化 变化 变化 变化 变化

Trong Python 2, câu lệnh in là một từ khóa.Trong Python 3, câu lệnh in là một hàm.Điều này có nghĩa là trong Python 3, bạn có thể sử dụng chức năng in với danh sách đối số, trong khi trong Python 2, bạn chỉ có thể sử dụng câu lệnh in với một đối số.

Ví dụ: trong Python 2, bạn sẽ viết mã sau để in chuỗi "Hello World":

`` `Python
In "Hello World"
`` `

Trong Python 3, bạn sẽ viết mã sau để in chuỗi "Hello World":

`` `Python
In ("Hello World")
`` `

Một sự khác biệt khác giữa câu lệnh in trong Python 2 và chức năng in trong Python 3 là câu lệnh in trong Python 2 không có ký tự dòng mới, trong khi chức năng in trong Python 3 có ký tự dòng mới.Điều này có nghĩa là nếu bạn sử dụng câu lệnh in trong Python 2, bạn sẽ cần thêm một ký tự mới vào cuối đầu ra nếu bạn muốn một dòng mới được in.

Ví dụ: mã sau trong Python 2 sẽ in chuỗi "Hello World" trên cùng một dòng với đầu ra trước:

`` `Python
In ("Hello World")
In ("Goodbye World")
`` `

Tuy nhiên, mã sau trong Python 3 sẽ in chuỗi "Hello World" trên một dòng mới, tiếp theo là chuỗi "Goodbye World" trên dòng tiếp theo:

`` `Python
In ("Hello World")
In ("Goodbye World")
`` `

Ngoài những thay đổi được đề cập ở trên, có một vài sự khác biệt nhỏ khác giữa câu lệnh in trong Python 2 và hàm in trong Python 3. Để biết thêm thông tin, vui lòng xem [Tài liệu Python] (https: //docs.python.org/3/thư viện/chức năng.html#in).

## hashtags

* #Python
* #python2
* #python3
* #in
* #
=======================================
#Python #python2 #python3 #print #语句 ## Python2 和 Python3 中 print 语句的变化

In Python 2, the print statement is a keyword. In Python 3, the print statement is a function. This means that in Python 3, you can use the print function with an argument list, while in Python 2, you can only use the print statement with a single argument.

For example, in Python 2, you would write the following code to print the string "Hello world":

```python
print "Hello world"
```

In Python 3, you would write the following code to print the string "Hello world":

```python
print("Hello world")
```

Another difference between the print statement in Python 2 and the print function in Python 3 is that the print statement in Python 2 does not have a trailing newline character, while the print function in Python 3 does have a trailing newline character. This means that if you use the print statement in Python 2, you will need to add a newline character to the end of your output if you want a new line to be printed.

For example, the following code in Python 2 will print the string "Hello world" on the same line as the previous output:

```python
print("Hello world")
print("Goodbye world")
```

However, the following code in Python 3 will print the string "Hello world" on a new line, followed by the string "Goodbye world" on the next line:

```python
print("Hello world")
print("Goodbye world")
```

In addition to the changes mentioned above, there are a few other minor differences between the print statement in Python 2 and the print function in Python 3. For more information, please see the [Python documentation](https://docs.python.org/3/library/functions.html#print).

## Hashtags

* #Python
* #python2
* #python3
* #print
* #语句
 
Join ToolsKiemTrieuDoGroup
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock