Hướng dẫn how many keywords in python latest version - có bao nhiêu từ khóa trong phiên bản mới nhất của python

Mã nguồn: lib/từ khóa.py Lib/keyword.py

Show

Mô -đun này cho phép chương trình Python xác định xem một chuỗi là từ khóa hay từ khóa mềm.keyword or soft keyword.

từ khóa.iskeyword (s) ¶iskeyword(s)

Trả về

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
6 nếu s là từ khóa Python.keyword.

Từ khóa.kwlist¶kwlist

Trình tự chứa tất cả các từ khóa được xác định cho trình thông dịch. Nếu bất kỳ từ khóa nào được xác định chỉ hoạt động khi các câu lệnh

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
7 cụ thể có hiệu lực, chúng cũng sẽ được bao gồm.keywords defined for the interpreter. If any keywords are defined to only be active when particular
>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
7 statements are in effect, these will be included as well.

Từ khóa.issoftkeyword (s) ¶issoftkeyword(s)

Trả về

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
6 Nếu s là từ khóa mềm Python.soft keyword.

Mới trong phiên bản 3.9.

Từ khóa.softkwlist¶softkwlist

Trình tự chứa tất cả các từ khóa mềm được xác định cho trình thông dịch. Nếu bất kỳ từ khóa mềm nào được xác định chỉ hoạt động khi các câu lệnh

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
7 cụ thể có hiệu lực, chúng cũng sẽ được bao gồm.soft keywords defined for the interpreter. If any soft keywords are defined to only be active when particular
>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
7 statements are in effect, these will be included as well.

Mới trong phiên bản 3.9.

Bal Krishna JHA Lượt xem: 2.08K Xuất bản: 24 tháng 1 năm 2020 Sửa đổi lần cuối: 9 tháng 2 năm 2020

Hướng dẫn how many keywords in python latest version - có bao nhiêu từ khóa trong phiên bản mới nhất của python

Có một số từ dành riêng được định nghĩa trong mọi ngôn ngữ, trong đó mỗi từ có một số chức năng liên quan đến nó. Các chức năng và từ khóa được quyết định bởi các nhà thiết kế ngôn ngữ và người sáng tạo. Trong Python 3.8, có 35 từ khóa. Danh sách các từ khóa tiếp tục thay đổi khi ngôn ngữ phát triển. Một từ khóa mới có thể được giới thiệu hoặc xóa, vì phiên bản mới của Python được phát hành.
In Python 3.8, there are 35 keywords. The list of keywords keeps changing as the language evolves. A new keyword may be introduced or deleted, as the new version of Python is released.

Ví dụ, trong Python 2.7, đã có & nbsp; 31 từ khóa so với 33 trong Python 3.6.7 và 35 trong Python 3.8.1.

Để liệt kê tất cả các từ khóa, bạn có thể sử dụng bất kỳ phương pháp nào:

Trong trình thông dịch Python, phương thức trợ giúp cuộc gọi -

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
0. Nó sẽ mở một lời nhắc trợ giúp tương tác. Ở đó bạn chỉ có thể viết
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
1. Nó sẽ hiển thị một danh sách tất cả các từ khóa.

Hướng dẫn how many keywords in python latest version - có bao nhiêu từ khóa trong phiên bản mới nhất của python

Nhưng phương pháp trên chỉ bị giới hạn ở chế độ tương tác. Trong trường hợp bạn muốn truy cập danh sách trong tập lệnh, bạn có thể nhập mô -đun từ khóa.

import keyword

print(keyword.kwlist())

Từ khóa trong Python 3.8.1

Từ khóaSự mô tả
Một toán tử logic
nhưĐược sử dụng để tạo ra một bí danh
khẳng địnhKiểm tra hai biểu thức
không đồng bộCoroutines
chờ đợiCoroutines
chờ đợiphá vỡ
Để thoát khỏi vòng lặplớp
Xác định một lớptiếp tục
Bỏ qua phần còn lại của khối mãdef
Xác định một hàmDel
Xóa một đối tượngElif
Có điều kiệnElif
Có điều kiệnkhác
ngoại trừĐược sử dụng để bắt một ngoại lệ
SaiGiá trị boolean
cuối cùngĐược sử dụng trong việc xử lý các ngoại lệ
Vòng lặp
từĐược sử dụng trong nhập chọn lọc từ một mô -đun
toàn cầuElif
Có điều kiệnkhác
ngoại trừĐược sử dụng để bắt một ngoại lệ
SaiGiá trị boolean
cuối cùngĐược sử dụng trong việc xử lý các ngoại lệ
Vòng lặp
từĐược sử dụng trong nhập chọn lọc từ một mô -đun
toàn cầuĐược sử dụng để khai báo một biến trong phạm vi toàn cầu
nếuMột toán tử logic
nhưĐược sử dụng để tạo ra một bí danh
khẳng địnhKiểm tra hai biểu thức
không đồng bộCoroutines
chờ đợiĐược sử dụng để bắt một ngoại lệ
SaiGiá trị boolean
cuối cùngĐược sử dụng trong việc xử lý các ngoại lệ
Vòng lặp
từĐược sử dụng trong nhập chọn lọc từ một mô -đun


toàn cầu

Được sử dụng để khai báo một biến trong phạm vi toàn cầu

Xem bây giờ hướng dẫn này có một khóa học video liên quan được tạo bởi nhóm Python thực sự. Xem cùng với hướng dẫn bằng văn bản để hiểu sâu hơn về sự hiểu biết của bạn: Khám phá các từ khóa trong Python This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Exploring Keywords in Python

Mỗi ngôn ngữ lập trình đều có các từ dành riêng, hoặc từ khóa, có ý nghĩa và hạn chế cụ thể xung quanh cách sử dụng chúng. Python không khác. Từ khóa Python là các khối xây dựng cơ bản của bất kỳ chương trình Python nào.keywords, that have specific meanings and restrictions around how they should be used. Python is no different. Python keywords are the fundamental building blocks of any Python program.

Trong bài viết này, bạn sẽ tìm thấy một giới thiệu cơ bản về tất cả các từ khóa Python cùng với các tài nguyên khác sẽ hữu ích để tìm hiểu thêm về từng từ khóa.

Đến cuối bài viết này, bạn sẽ có thể:

  • Xác định từ khóa Python Python keywords
  • Hiểu những gì mỗi từ khóa được sử dụng cho what each keyword is used for
  • Làm việc với các từ khóa được lập trình bằng cách sử dụng mô -đun
    >>> def func():
    ...     print("hello")
    ...
    >>> x = func()
    hello
    >>> print(x)
    None
    
    2
    with keywords programmatically using the
    >>> def func():
    ...     print("hello")
    ...
    >>> x = func()
    hello
    >>> print(x)
    None
    
    2 module

Từ khóa Python

Từ khóa Python là những từ dành riêng đặc biệt có ý nghĩa và mục đích cụ thể và có thể được sử dụng cho bất cứ điều gì ngoại trừ những mục đích cụ thể đó. Các từ khóa này luôn có sẵn, bạn sẽ không bao giờ phải nhập chúng vào mã của bạn.

Các từ khóa Python khác với các chức năng và loại tích hợp Python. Các chức năng và loại tích hợp cũng luôn có sẵn, nhưng chúng không bị hạn chế như các từ khóa trong việc sử dụng của chúng.

Một ví dụ về một cái gì đó bạn có thể làm với các từ khóa Python là gán một cái gì đó cho chúng. Nếu bạn cố gắng, thì bạn sẽ nhận được

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
3. Bạn đã giành được một
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
3 nếu bạn cố gắng gán một cái gì đó cho một chức năng hoặc loại tích hợp, nhưng nó vẫn không phải là một ý tưởng tốt. Để có thể giải thích sâu hơn về các cách từ khóa có thể bị sử dụng sai, hãy xem cú pháp không hợp lệ trong Python: Lý do phổ biến cho cú pháp.

Kể từ Python 3.8, có ba mươi lăm từ khóa trong Python. Ở đây họ có liên kết đến các phần có liên quan trong suốt phần còn lại của bài viết này:

Bạn có thể sử dụng các liên kết này để nhảy vào các từ khóa mà bạn muốn đọc, hoặc bạn có thể tiếp tục đọc cho một tour du lịch có hướng dẫn.

Cách xác định từ khóa Python

Danh sách các từ khóa Python đã thay đổi theo thời gian. Ví dụ: từ khóa

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
5 và
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 weren được thêm vào cho đến khi Python 3.7. Ngoài ra, cả
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
7 và
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
8 đều là từ khóa trong Python 2.7 nhưng đã được biến thành các hàm tích hợp trong Python 3+ và không còn xuất hiện trong danh sách các từ khóa.

Trong các phần dưới đây, bạn sẽ học được một số cách để biết hoặc tìm ra từ nào là từ khóa trong Python.

Sử dụng IDE với cú pháp làm nổi bật

Có rất nhiều id python tốt ngoài kia. Tất cả chúng sẽ làm nổi bật các từ khóa để phân biệt chúng với các từ khác trong mã của bạn. Điều này sẽ giúp bạn nhanh chóng xác định các từ khóa Python trong khi bạn lập trình để bạn không sử dụng chúng không chính xác.

Sử dụng mã trong một bản sao để kiểm tra các từ khóa

Trong Python Repl, có một số cách bạn có thể xác định các từ khóa Python hợp lệ và tìm hiểu thêm về chúng.

Bạn có thể nhận được danh sách các từ khóa có sẵn bằng cách sử dụng

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
0:

>>>

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not

Tiếp theo, như được chỉ ra trong đầu ra ở trên, bạn có thể sử dụng một lần nữa bằng cách truyền trong từ khóa cụ thể mà bạn cần thêm thông tin về. Bạn có thể làm điều này, ví dụ, với từ khóa

left if not left else right
1:

>>>

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)

Tiếp theo, như được chỉ ra trong đầu ra ở trên, bạn có thể sử dụng một lần nữa bằng cách truyền trong từ khóa cụ thể mà bạn cần thêm thông tin về. Bạn có thể làm điều này, ví dụ, với từ khóa

left if not left else right
1:

  1. Python cũng cung cấp một mô -đun
    >>> def func():
    ...     print("hello")
    ...
    >>> x = func()
    hello
    >>> print(x)
    None
    
    2 để làm việc với các từ khóa Python theo cách lập trình. Mô -đun
    >>> def func():
    ...     print("hello")
    ...
    >>> x = func()
    hello
    >>> print(x)
    None
    
    2 trong Python cung cấp hai thành viên hữu ích để xử lý các từ khóa:
    provides a list of all the Python keywords for the version of Python you’re running.
  2. left if not left else right
    
    4 cung cấp một danh sách tất cả các từ khóa Python cho phiên bản Python mà bạn đang chạy.
    provides a handy way to determine if a string is also a keyword.

left if not left else right
5 cung cấp một cách tiện dụng để xác định xem một chuỗi cũng là từ khóa.

>>>

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35

Tiếp theo, như được chỉ ra trong đầu ra ở trên, bạn có thể sử dụng một lần nữa bằng cách truyền trong từ khóa cụ thể mà bạn cần thêm thông tin về. Bạn có thể làm điều này, ví dụ, với từ khóa

left if not left else right
1:

Python cũng cung cấp một mô -đun >>> def func(): ... print("hello") ... >>> x = func() hello >>> print(x) None 2 để làm việc với các từ khóa Python theo cách lập trình. Mô -đun >>> def func(): ... print("hello") ... >>> x = func() hello >>> print(x) None 2 trong Python cung cấp hai thành viên hữu ích để xử lý các từ khóa:

left if not left else right
4 cung cấp một danh sách tất cả các từ khóa Python cho phiên bản Python mà bạn đang chạy.

left if not left else right 5 cung cấp một cách tiện dụng để xác định xem một chuỗi cũng là từ khóa.

Để có được danh sách tất cả các từ khóa trong phiên bản Python mà bạn đang chạy và để nhanh chóng xác định có bao nhiêu từ khóa được xác định, hãy sử dụng

left if not left else right
6:

Nếu bạn cần biết thêm về một từ khóa hoặc cần làm việc với các từ khóa theo cách lập trình, thì Python cung cấp tài liệu và công cụ này cho bạn.

  • Tìm kiếm một

    >>> def func():
    ...     print("hello")
    ...
    >>> x = func()
    hello
    >>> print(x)
    None
    
    3 refers to the Boolean evaluation of a value. The truthiness of a value indicates whether the value is truthy or falsy.

  • Cuối cùng, một chỉ số khác cho thấy một từ mà bạn sử dụng thực sự là một từ khóa là nếu bạn nhận được

    >>> def func():
    ...     print("hello")
    ...
    >>> x = func()
    hello
    >>> print(x)
    None
    
    3 trong khi cố gắng gán cho nó, đặt tên cho một hàm với nó hoặc làm một cái gì đó khác được phép với nó. Điều này khó phát hiện hơn một chút, nhưng đó là một cách mà Python sẽ cho bạn biết bạn sử dụng từ khóa không chính xác. means any value that evaluates to true in the Boolean context. To determine if a value is truthy, pass it as the argument to
    left if not left else right
    
    9. If it returns
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    0, then the value is truthy. Examples of truthy values are non-empty strings, any numbers that aren’t
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    1, non-empty lists, and many more.

  • Từ khóa Python và cách sử dụng của chúng means any value that evaluates to false in the Boolean context. To determine if a value is falsy, pass it as the argument to

    left if not left else right
    
    9. If it returns
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    3, then the value is falsy. Examples of falsy values are
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    4,
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    1,
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    6,
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    7, and
    >>> val = ""  # Truthiness value is `False`
    >>> not val
    True
    
    >>> val = 5  # Truthiness value is `True`
    >>> not val
    False
    
    8.

Các phần dưới đây tổ chức các từ khóa Python thành các nhóm dựa trên việc sử dụng của chúng. Ví dụ, nhóm đầu tiên là tất cả các từ khóa được sử dụng làm giá trị và nhóm thứ hai là từ khóa được sử dụng làm toán tử. Các nhóm này sẽ giúp bạn hiểu rõ hơn về cách sử dụng từ khóa và cung cấp một cách tốt đẹp để tổ chức danh sách dài các từ khóa Python.

Có một vài thuật ngữ được sử dụng trong các phần dưới đây có thể là mới đối với bạn. Họ đã định nghĩa ở đây và bạn nên biết về ý nghĩa của chúng trước khi tiến hành:

Sự trung thực đề cập đến việc đánh giá boolean về một giá trị. Sự thật của một giá trị cho thấy giá trị là sự thật hay giả.

Sự thật có nghĩa là bất kỳ giá trị nào đánh giá đúng trong bối cảnh Boolean. Để xác định xem một giá trị có phải là sự thật hay không, hãy truyền nó như là đối số cho
left if not left else right
9. Nếu nó trả về
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0, thì giá trị là sự thật. Ví dụ về các giá trị sự thật là các chuỗi không trống, bất kỳ số nào aren ____ ____991, danh sách không trống và nhiều thứ khác.

Falsy có nghĩa là bất kỳ giá trị nào đánh giá sai trong bối cảnh Boolean. Để xác định xem một giá trị có phải là giả mạo hay không, hãy truyền nó làm đối số cho

left if not left else right
9. Nếu nó trả về
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3, thì giá trị là giả. Ví dụ về các giá trị giả là
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
4,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
1,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
6,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
7 và
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
8.
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0
keyword is used as the Boolean true value in Python code. The Python keyword
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3
is similar to the
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 keyword, but with the opposite Boolean value of false. In other programming languages, you’ll see these keywords written in lowercase (
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
07 and
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
08), but in Python they are always written in uppercase.

Các từ khóa Python

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 và
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 có thể được gán cho các biến và so sánh với trực tiếp:

>>>

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True

Hầu hết các giá trị trong Python sẽ đánh giá đến

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 khi được chuyển đến
left if not left else right
9. Chỉ có một vài giá trị trong Python sẽ đánh giá thành
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 khi được chuyển đến
left if not left else right
9:
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
1,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
4,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
6 và
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
7 để đặt tên cho một số. Chuyển giá trị cho
left if not left else right
9 cho thấy độ thật của giá trị, hoặc giá trị boolean tương đương. Bạn có thể so sánh độ thật của giá trị với
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 bằng cách chuyển giá trị cho
left if not left else right
9:

>>>

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True

Hầu hết các giá trị trong Python sẽ đánh giá đến

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 khi được chuyển đến
left if not left else right
9. Chỉ có một vài giá trị trong Python sẽ đánh giá thành
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 khi được chuyển đến
left if not left else right
9:
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
1,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
4,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
6 và
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
7 để đặt tên cho một số. Chuyển giá trị cho
left if not left else right
9 cho thấy độ thật của giá trị, hoặc giá trị boolean tương đương. Bạn có thể so sánh độ thật của giá trị với
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 bằng cách chuyển giá trị cho
left if not left else right
9:
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25
doesn’t work. You should directly compare a value to
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 or
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 only if you want to know whether it is actually the values
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 or
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3.

Lưu ý rằng việc so sánh giá trị sự thật trực tiếp với

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 bằng cách sử dụng
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25 không hoạt động. Bạn nên so sánh trực tiếp một giá trị với
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 chỉ khi bạn muốn biết liệu đó có thực sự là các giá trị
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hay
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3.

>>>

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy

Hầu hết các giá trị trong Python sẽ đánh giá đến

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 khi được chuyển đến
left if not left else right
9. Chỉ có một vài giá trị trong Python sẽ đánh giá thành
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 khi được chuyển đến
left if not left else right
9:
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
1,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
4,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
6 và
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
7 để đặt tên cho một số. Chuyển giá trị cho
left if not left else right
9 cho thấy độ thật của giá trị, hoặc giá trị boolean tương đương. Bạn có thể so sánh độ thật của giá trị với
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 bằng cách chuyển giá trị cho
left if not left else right
9:

Lưu ý rằng việc so sánh giá trị sự thật trực tiếp với
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 bằng cách sử dụng
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25 không hoạt động. Bạn nên so sánh trực tiếp một giá trị với
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 chỉ khi bạn muốn biết liệu đó có thực sự là các giá trị
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hay
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3.

Khi viết các câu lệnh có điều kiện dựa trên sự thật của một giá trị, bạn không nên so sánh trực tiếp với

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3. Bạn có thể dựa vào Python để kiểm tra sự thật trong các điều kiện cho bạn:
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01
represents no value. In other programming languages,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01 is represented as
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
37,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
38,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
39,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
40, or
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
41.

Trong Python, bạn thường không cần phải chuyển đổi các giá trị để được rõ ràng

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3. Python sẽ ngầm xác định sự thật của giá trị cho bạn.

>>>

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None

Hầu hết các giá trị trong Python sẽ đánh giá đến

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 khi được chuyển đến
left if not left else right
9. Chỉ có một vài giá trị trong Python sẽ đánh giá thành
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 khi được chuyển đến
left if not left else right
9:
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
1,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
4,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
6 và
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
7 để đặt tên cho một số. Chuyển giá trị cho
left if not left else right
9 cho thấy độ thật của giá trị, hoặc giá trị boolean tương đương. Bạn có thể so sánh độ thật của giá trị với
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 bằng cách chuyển giá trị cho
left if not left else right
9:

Lưu ý rằng việc so sánh giá trị sự thật trực tiếp với >>> val = "" # Truthiness value is `False` >>> not val True >>> val = 5 # Truthiness value is `True` >>> not val False 0 hoặc >>> val = "" # Truthiness value is `False` >>> not val True >>> val = 5 # Truthiness value is `True` >>> not val False 3 bằng cách sử dụng >>> help("keywords") Here is a list of the Python keywords. Enter any keyword to get more help. False class from or None continue global pass True def if raise and del import return as elif in try assert else is while async except lambda with await finally nonlocal yield break for not 25 không hoạt động. Bạn nên so sánh trực tiếp một giá trị với >>> val = "" # Truthiness value is `False` >>> not val True >>> val = 5 # Truthiness value is `True` >>> not val False 0 hoặc >>> val = "" # Truthiness value is `False` >>> not val True >>> val = 5 # Truthiness value is `True` >>> not val False 3 chỉ khi bạn muốn biết liệu đó có thực sự là các giá trị >>> val = "" # Truthiness value is `False` >>> not val True >>> val = 5 # Truthiness value is `True` >>> not val False 0 hay >>> val = "" # Truthiness value is `False` >>> not val True >>> val = 5 # Truthiness value is `True` >>> not val False 3.

Khi viết các câu lệnh có điều kiện dựa trên sự thật của một giá trị, bạn không nên so sánh trực tiếp với

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3. Bạn có thể dựa vào Python để kiểm tra sự thật trong các điều kiện cho bạn:

Trong Python, bạn thường không cần phải chuyển đổi các giá trị để được rõ ràng
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3. Python sẽ ngầm xác định sự thật của giá trị cho bạn.
Từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01
Từ khóa Python
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01 đại diện cho không có giá trị. Trong các ngôn ngữ lập trình khác,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01 được biểu thị là
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
37,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
38,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
39,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
40 hoặc
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
41.
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01 cũng là giá trị mặc định được trả về bởi một hàm nếu nó không có câu lệnh
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43:
Để đi sâu hơn về từ khóa Python rất quan trọng và hữu ích này, hãy xem NULL trong Python: Hiểu đối tượng Python tựa Nonetype.Từ khóa của nhà điều hành:
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25
Một số từ khóa Python được sử dụng làm toán tử. Trong các ngôn ngữ lập trình khác, các nhà khai thác này sử dụng các biểu tượng như
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
49,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
50 và
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
51. Các toán tử Python cho đây đều là tất cả các từ khóa:
Toán học toánNhững ngôn ngữ khác
Từ khóa PythonVà, ∧
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
52
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44
Hoặc, ∨
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
54
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45
Không, ¬

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
51

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46

Chứa,

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 is used to determine if both the left and right operands are truthy or falsy. If both operands are truthy, then the result will be truthy. If one is falsy, then the result will be falsy:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47

XÁC THỰC

left if not left else right

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
59

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25

Mã Python được thiết kế cho khả năng đọc. Đó là lý do tại sao nhiều nhà khai thác sử dụng các biểu tượng trong các ngôn ngữ lập trình khác là các từ khóa trong Python.

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44

Từ khóa Python
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 được sử dụng để xác định xem cả hai toán hạng bên trái và phải là sự thật hay giả. Nếu cả hai toán hạng là sự thật, thì kết quả sẽ là sự thật. Nếu một người là giả, thì kết quả sẽ là giả mạo:

Lưu ý rằng kết quả của câu lệnh

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 sẽ không nhất thiết là
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3. Điều này là do hành vi kỳ quặc của
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44. Thay vì đánh giá các toán hạng theo các giá trị boolean của chúng,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 chỉ cần trả lại
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
68 nếu nó là giả mạo nếu không nó sẽ trả về
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
69. Kết quả của một câu lệnh
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 có thể được chuyển đến
left if not left else right
9 để có được giá trị
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 rõ ràng hoặc chúng có thể được sử dụng trong một câu lệnh
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 có điều kiện.
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45
keyword is used to determine if at least one of the operands is truthy. An
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45 statement returns the first operand if it is truthy and otherwise returns the second operand:

Nếu bạn muốn xác định một biểu thức đã làm điều tương tự như biểu thức

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44, nhưng không sử dụng từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44, thì bạn có thể sử dụng toán tử python ternary:

Tuyên bố trên sẽ tạo ra kết quả tương tự như

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
77.

Bởi vì

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 trả về toán hạng đầu tiên nếu nó Falsy và nếu không thì trả về toán hạng cuối cùng, bạn cũng có thể sử dụng
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 trong một bài tập:

Để có cái nhìn sâu hơn về

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45, bạn có thể đọc về cách sử dụng toán tử Python
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45.

Từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46

Từ khóa Python từ

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46 được sử dụng để có được giá trị boolean ngược lại của một biến:
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46
keyword is used to get the opposite Boolean value of a variable:

>>>

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46 được sử dụng trong các câu lệnh có điều kiện hoặc các biểu thức boolean khác để lật ý nghĩa hoặc kết quả của boolean. Không giống như
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 và
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46 sẽ xác định giá trị boolean rõ ràng,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3, sau đó trả lại ngược lại.
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44
and
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45
,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46
will determine the explicit Boolean value,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 or
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3, and then return the opposite.

Nếu bạn muốn có được hành vi tương tự mà không cần sử dụng

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46, thì bạn có thể làm như vậy với biểu thức ternary sau:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
0

Tuyên bố này sẽ trả về kết quả tương tự như

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
04.

Từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47

Từ khóa Python từ

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 là một kiểm tra ngăn chặn mạnh mẽ hoặc toán tử thành viên. Cho một phần tử để tìm và một container hoặc chuỗi để tìm kiếm,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 sẽ trả về
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 cho biết liệu phần tử có được tìm thấy trong container hay không:
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47
keyword is a powerful containment check, or membership operator. Given an element to find and a container or sequence to search,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 will return
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 or
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 indicating whether the element was found in the container:

Một ví dụ tốt về việc sử dụng từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 đang kiểm tra một chữ cái cụ thể trong một chuỗi:

>>>

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
1

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46 được sử dụng trong các câu lệnh có điều kiện hoặc các biểu thức boolean khác để lật ý nghĩa hoặc kết quả của boolean. Không giống như
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
44 và
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
45,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46 sẽ xác định giá trị boolean rõ ràng,
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3, sau đó trả lại ngược lại.

Nếu bạn muốn có được hành vi tương tự mà không cần sử dụng
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
46, thì bạn có thể làm như vậy với biểu thức ternary sau:

Tuyên bố này sẽ trả về kết quả tương tự như

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
04.
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25
keyword is an identity check. This is different from the
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
15 operator, which checks for equality. Sometimes two things can be considered equal but not be the exact same object in memory. The
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25 keyword determines whether two objects are exactly the same object:

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47

Từ khóa Python từ

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 là một kiểm tra ngăn chặn mạnh mẽ hoặc toán tử thành viên. Cho một phần tử để tìm và một container hoặc chuỗi để tìm kiếm,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 sẽ trả về
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hoặc
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3 cho biết liệu phần tử có được tìm thấy trong container hay không:

Một ví dụ tốt về việc sử dụng từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 đang kiểm tra một chữ cái cụ thể trong một chuỗi:

Từ khóa >>> help("keywords") Here is a list of the Python keywords. Enter any keyword to get more help. False class from or None continue global pass True def if raise and del import return as elif in try assert else is while async except lambda with await finally nonlocal yield break for not 47 hoạt động với tất cả các loại container: danh sách, dicts, bộ, chuỗi và bất cứ thứ gì khác xác định >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 12 hoặc có thể được lặp lại.

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25

Từ khóa Python từ
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25 là một kiểm tra nhận dạng. Điều này khác với toán tử
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
15, kiểm tra sự bình đẳng. Đôi khi hai điều có thể được coi là bằng nhau nhưng không phải là cùng một đối tượng trong bộ nhớ. Từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25 xác định xem hai đối tượng có chính xác cùng một đối tượng hay không:

Điều này sẽ trả về

>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 nếu
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
18 là cùng một đối tượng chính xác trong bộ nhớ là
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
19, nếu không nó sẽ trả về
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3.
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74
keyword is used to start a conditional statement. An
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 statement allows you to write a block of code that gets executed only if the expression after
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 is truthy.

Hầu hết thời gian bạn sẽ thấy

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25 được sử dụng để kiểm tra xem một đối tượng là
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01. Vì
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01 là một singleton, chỉ có một trường hợp của
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01 có thể tồn tại, do đó, tất cả các giá trị
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
01 là cùng một đối tượng chính xác trong bộ nhớ.

Nếu các khái niệm này là mới đối với bạn, thì bạn có thể nhận được lời giải thích sâu hơn bằng cách kiểm tra Python ‘! Để tìm hiểu sâu hơn về cách

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
25 hoạt động, hãy xem các nhà khai thác và biểu thức trong Python.

Kiểm soát luồng từ khóa:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74,
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28,
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
2

Ba từ khóa Python được sử dụng cho luồng điều khiển:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74,
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28 và
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29. Các từ khóa Python này cho phép bạn sử dụng logic có điều kiện và thực thi mã được đưa ra một số điều kiện nhất định. Các từ khóa này rất phổ biến, chúng sẽ được sử dụng trong hầu hết các chương trình bạn thấy hoặc viết bằng Python.

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
3

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74

Từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 được sử dụng để bắt đầu một câu lệnh có điều kiện. Một câu lệnh
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 cho phép bạn viết một khối mã chỉ được thực thi nếu biểu thức sau
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 là sự thật.

Cú pháp cho câu lệnh

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 bắt đầu với từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 ở đầu dòng, theo sau là một biểu thức hợp lệ sẽ được đánh giá về giá trị chân thực của nó:
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28
statement looks and functions like the
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 statement, with two major differences:

  1. Tuyên bố
    >>> help("keywords")
    
    Here is a list of the Python keywords.  Enter any keyword to get more help.
    
    False               class               from                or
    None                continue            global              pass
    True                def                 if                  raise
    and                 del                 import              return
    as                  elif                in                  try
    assert              else                is                  while
    async               except              lambda              with
    await               finally             nonlocal            yield
    break               for                 not
    
    74 là một thành phần quan trọng của hầu hết các chương trình. Để biết thêm thông tin về tuyên bố
    >>> help("keywords")
    
    Here is a list of the Python keywords.  Enter any keyword to get more help.
    
    False               class               from                or
    None                continue            global              pass
    True                def                 if                  raise
    and                 del                 import              return
    as                  elif                in                  try
    assert              else                is                  while
    async               except              lambda              with
    await               finally             nonlocal            yield
    break               for                 not
    
    74, hãy xem các câu lệnh có điều kiện trong Python.
  2. Một cách sử dụng khác của từ khóa
    >>> help("keywords")
    
    Here is a list of the Python keywords.  Enter any keyword to get more help.
    
    False               class               from                or
    None                continue            global              pass
    True                def                 if                  raise
    and                 del                 import              return
    as                  elif                in                  try
    assert              else                is                  while
    async               except              lambda              with
    await               finally             nonlocal            yield
    break               for                 not
    
    74 là một phần của toán tử ternary Python:

Đây là phiên bản một dòng của câu lệnh

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
42 bên dưới:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
4

Nếu các biểu thức của bạn là các câu lệnh không biến chứng, thì sử dụng biểu thức ternary cung cấp một cách tốt đẹp để đơn giản hóa mã của bạn một chút. Khi các điều kiện trở nên phức tạp, nó thường tốt hơn để dựa vào tuyên bố

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 tiêu chuẩn.

Từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28

Tuyên bố

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28 trông và chức năng như câu lệnh
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74, với hai khác biệt chính:
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29
statement, in conjunction with the Python keywords
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 and
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28, denotes a block of code that should be executed only if the other conditional blocks,
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 and
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28, are all falsy:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
5

Lưu ý rằng câu lệnh

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 không có biểu thức có điều kiện. Kiến thức về từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
28 và
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 và việc sử dụng đúng của chúng là rất quan trọng đối với các lập trình viên Python. Cùng với
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74, chúng tạo thành một số thành phần được sử dụng thường xuyên nhất trong bất kỳ chương trình Python nào.

Từ khóa lặp lại: >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 71, >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 72, >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 73, >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 74, >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 29

Vòng lặp và lặp là các khái niệm lập trình cực kỳ quan trọng. Một số từ khóa Python được sử dụng để tạo và làm việc với các vòng lặp. Chúng, giống như các từ khóa Python được sử dụng cho các điều kiện ở trên, sẽ được sử dụng và nhìn thấy trong mọi chương trình Python bạn gặp. Hiểu chúng và cách sử dụng đúng đắn của họ sẽ giúp bạn cải thiện như một lập trình viên Python.

Từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71

Vòng lặp phổ biến nhất trong Python là vòng

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71. Nó được xây dựng bằng cách kết hợp các từ khóa Python
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 và
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 đã giải thích trước đó. Cú pháp cơ bản cho vòng lặp
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 như sau:
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71
and
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47
explained earlier. The basic syntax for a
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 loop is as follows:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
6

Một ví dụ phổ biến là lặp qua các số một đến năm và in chúng ra màn hình:

>>>

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
7

Trong các ngôn ngữ lập trình khác, cú pháp cho vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 sẽ trông hơi khác một chút. Bạn thường cần chỉ định biến, điều kiện để tiếp tục và cách tăng biến đó (
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
82).

Trong Python, vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 giống như một vòng lặp lại trong các ngôn ngữ lập trình khác. Đưa đối tượng để lặp lại, nó gán giá trị của từng lần lặp cho biến:

>>>

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
8

Trong các ngôn ngữ lập trình khác, cú pháp cho vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 sẽ trông hơi khác một chút. Bạn thường cần chỉ định biến, điều kiện để tiếp tục và cách tăng biến đó (
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
82).

Trong Python, vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 giống như một vòng lặp lại trong các ngôn ngữ lập trình khác. Đưa đối tượng để lặp lại, nó gán giá trị của từng lần lặp cho biến:

Trong ví dụ này, bạn bắt đầu với danh sách (container) của những người tên. Vòng lặp
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 bắt đầu với từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 ở đầu dòng, theo sau là biến để gán từng phần tử của danh sách, sau đó là từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 và cuối cùng là container (
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
87).

Python sườn

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 Loop là một thành phần chính khác trong bất kỳ chương trình Python nào. Để tìm hiểu thêm về các vòng
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71, hãy xem Python Hồi cho các vòng lặp (lặp lại xác định).
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72
and works like a
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 loop in other programming languages. As long as the condition that follows the
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 keyword is truthy, the block following the
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 statement will continue to be executed over and over again:

Từ khóa

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72

Vòng lặp Python từ

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 sử dụng từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 và hoạt động giống như vòng lặp
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 trong các ngôn ngữ lập trình khác. Miễn là điều kiện theo sau từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 là sự thật, khối theo câu lệnh
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 sẽ tiếp tục được thực thi nhiều lần:

>>>

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
0

Trong các ngôn ngữ lập trình khác, cú pháp cho vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 sẽ trông hơi khác một chút. Bạn thường cần chỉ định biến, điều kiện để tiếp tục và cách tăng biến đó (
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
82).

Trong Python, vòng lặp
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 giống như một vòng lặp lại trong các ngôn ngữ lập trình khác. Đưa đối tượng để lặp lại, nó gán giá trị của từng lần lặp cho biến:

Trong ví dụ này, bạn bắt đầu với danh sách (container) của những người tên. Vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 bắt đầu với từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 ở đầu dòng, theo sau là biến để gán từng phần tử của danh sách, sau đó là từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 và cuối cùng là container (
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
87).
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
73
keyword. This keyword will work in both
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 and
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 loops:

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
1

Python sườn

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 Loop là một thành phần chính khác trong bất kỳ chương trình Python nào. Để tìm hiểu thêm về các vòng
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71, hãy xem Python Hồi cho các vòng lặp (lặp lại xác định).

>>>

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
2

Trong các ngôn ngữ lập trình khác, cú pháp cho vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 sẽ trông hơi khác một chút. Bạn thường cần chỉ định biến, điều kiện để tiếp tục và cách tăng biến đó (
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
82).

Trong Python, vòng lặp
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 giống như một vòng lặp lại trong các ngôn ngữ lập trình khác. Đưa đối tượng để lặp lại, nó gán giá trị của từng lần lặp cho biến:

Trong ví dụ này, bạn bắt đầu với danh sách (container) của những người tên. Vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 bắt đầu với từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 ở đầu dòng, theo sau là biến để gán từng phần tử của danh sách, sau đó là từ khóa
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
47 và cuối cùng là container (
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
87).
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
74
keyword for when you want to skip to the next loop iteration. Like in most other programming languages, the
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
74 keyword allows you to stop executing the current loop iteration and move on to the next iteration:

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
3

Python sườn

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 Loop là một thành phần chính khác trong bất kỳ chương trình Python nào. Để tìm hiểu thêm về các vòng
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71, hãy xem Python Hồi cho các vòng lặp (lặp lại xác định).

Từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72

Vòng lặp Python từ

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 sử dụng từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 và hoạt động giống như vòng lặp
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 trong các ngôn ngữ lập trình khác. Miễn là điều kiện theo sau từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 là sự thật, khối theo câu lệnh
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 sẽ tiếp tục được thực thi nhiều lần:
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29
keyword specifies code that should be run if the loop exits normally, meaning
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
73 was not called to exit the loop early.

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
9

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
4

Cách dễ nhất để chỉ định một vòng lặp vô hạn trong Python là sử dụng từ khóa

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72 với một biểu thức luôn là sự thật:

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
5

Để biết thêm các ví dụ về các vòng lặp vô hạn trong hành động, hãy xem chương trình ổ cắm trong Python (Hướng dẫn). Để tìm hiểu thêm về các vòng

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
72, hãy xem Python, trong khi các vòng lặp (lặp không xác định).

Nhiệm vụ mà nó hiển thị là lặp qua các số từ hai đến chín để tìm các số nguyên tố. Một cách bạn có thể làm điều này là với vòng lặp

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 tiêu chuẩn với biến cờ:flag variable:

>>>

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
6

Bạn có thể sử dụng cờ

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 để cho biết cách thoát vòng. Nếu nó thoát ra bình thường, thì cờ
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 vẫn ở mức
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0. Nếu nó thoát ra với
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
73, thì cờ
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 sẽ được đặt thành
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3. Khi ở ngoài vòng
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 bên trong, bạn có thể kiểm tra cờ để xác định xem
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 có phải là
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hay không và nếu vậy, in rằng số đó là số nguyên tố.

Khối

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 cung cấp cú pháp đơn giản hơn. Nếu bạn thấy mình phải đặt cờ trong một vòng lặp, thì hãy xem ví dụ tiếp theo như một cách để có khả năng đơn giản hóa mã của bạn:

>>>

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
7

Bạn có thể sử dụng cờ

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 để cho biết cách thoát vòng. Nếu nó thoát ra bình thường, thì cờ
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 vẫn ở mức
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0. Nếu nó thoát ra với
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
73, thì cờ
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 sẽ được đặt thành
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
3. Khi ở ngoài vòng
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
71 bên trong, bạn có thể kiểm tra cờ để xác định xem
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
28 có phải là
>>> val = ""  # Truthiness value is `False`
>>> not val
True

>>> val = 5  # Truthiness value is `True`
>>> not val
False
0 hay không và nếu vậy, in rằng số đó là số nguyên tố.

Khối

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 cung cấp cú pháp đơn giản hơn. Nếu bạn thấy mình phải đặt cờ trong một vòng lặp, thì hãy xem ví dụ tiếp theo như một cách để có khả năng đơn giản hóa mã của bạn:

Điều duy nhất bạn cần làm để sử dụng khối >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 29 trong ví dụ này là xóa cờ >>> import keyword >>> keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'async', ... >>> len(keyword.kwlist) 35 28 và thay thế câu lệnh >>> help("keywords") Here is a list of the Python keywords. Enter any keyword to get more help. False class from or None continue global pass True def if raise and del import return as elif in try assert else is while async except lambda with await finally nonlocal yield break for not 74 cuối cùng bằng khối >>> help("pass") The "pass" statement ******************** pass_stmt ::= "pass" "pass" is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet) 29. Điều này cuối cùng tạo ra kết quả tương tự như ví dụ trước đây, chỉ với mã rõ ràng hơn.

Đôi khi sử dụng từ khóa

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 với một vòng lặp có vẻ hơi lạ, nhưng một khi bạn hiểu rằng nó cho phép bạn tránh sử dụng cờ trong vòng lặp của mình, nó có thể là một công cụ mạnh mẽ.

Từ khóa cấu trúc:
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43,
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
44,
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45,
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46,
left if not left else right
1,
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48

Để xác định các chức năng và các lớp hoặc sử dụng các trình quản lý ngữ cảnh, bạn sẽ cần sử dụng một trong các từ khóa Python trong phần này. Họ là một phần thiết yếu của ngôn ngữ Python và sự hiểu biết khi nào nên sử dụng chúng sẽ giúp bạn trở thành một lập trình viên Python tốt hơn.

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43 is used to define a function or method of a class. This is equivalent to
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
51 in JavaScript and PHP. The basic syntax for defining a function with
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43 looks like this:

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
8

Từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43

Từ khóa Python từ
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43 được sử dụng để xác định hàm hoặc phương thức của một lớp. Điều này tương đương với
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
51 trong JavaScript và PHP. Cú pháp cơ bản để xác định chức năng với
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43 trông như thế này:

Các chức năng và phương pháp có thể là các cấu trúc rất hữu ích trong bất kỳ chương trình Python nào. Để tìm hiểu thêm về việc xác định chúng và tất cả các trong và ngoài của chúng, hãy xem xác định chức năng Python của riêng bạn.

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
44 is as follows:

Từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
44

Để xác định một lớp trong Python, bạn sử dụng từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
44. Cú pháp chung để xác định một lớp có
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
44 như sau:

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
9

Các lớp là các công cụ mạnh mẽ trong lập trình hướng đối tượng và bạn nên biết về chúng và cách xác định chúng. Để tìm hiểu thêm, hãy xem chương trình hướng đối tượng (OOP) trong Python 3.

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 keyword:

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
0

Từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45

Các nhà quản lý bối cảnh là một cấu trúc thực sự hữu ích trong Python. Mỗi Trình quản lý bối cảnh thực hiện mã cụ thể trước và sau các câu lệnh bạn chỉ định. Để sử dụng một, bạn sử dụng từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45:

>>>

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
1

Sử dụng

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 cung cấp cho bạn một cách để xác định mã sẽ được thực thi trong phạm vi Trình quản lý ngữ cảnh. Ví dụ cơ bản nhất về điều này là khi bạn làm việc với I/O tệp trong Python.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45
keyword opens the file for reading, assigns the open file pointer to
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
62, then executes whatever code you specify in the
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 block. Then, after the block is executed, the file pointer closes. Even if your code in the
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 block raises an exception, the file pointer would still close.

Nếu bạn muốn mở một tệp, hãy làm một cái gì đó với tệp đó và sau đó đảm bảo rằng tệp đã được đóng chính xác, sau đó bạn sẽ sử dụng trình quản lý ngữ cảnh. Hãy xem xét ví dụ này trong đó

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
59 chứa một danh sách các tên, một dòng trên mỗi dòng:

Trình quản lý bối cảnh I/O File được cung cấp bởi
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
60 và được bắt đầu với từ khóa
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 mở tệp để đọc, gán con trỏ tệp mở thành
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
62, sau đó thực thi bất kỳ mã nào bạn chỉ định trong khối
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45. Sau đó, sau khi khối được thực thi, con trỏ tệp đóng. Ngay cả khi mã của bạn trong khối
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 tăng ngoại lệ, con trỏ tệp vẫn sẽ đóng.

Để biết ví dụ tuyệt vời về việc sử dụng

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 và người quản lý bối cảnh, hãy xem các hàm của Python Timer: ba cách để theo dõi mã của bạn.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46
. You may have also seen
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46 used to alias imports and exceptions, and this is no different. The alias is available in the
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 block:

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
2

Từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46 được sử dụng với
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45

Nếu bạn muốn truy cập vào kết quả của biểu thức hoặc trình quản lý ngữ cảnh được chuyển sang
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45, bạn sẽ cần phải bí danh bằng cách sử dụng
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46. Bạn cũng có thể đã thấy
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46 được sử dụng để nhập khẩu bí danh và ngoại lệ, và điều này không khác. Bí danh có sẵn trong khối
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45:

Hầu hết thời gian, bạn sẽ thấy hai từ khóa Python này,

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
45 và
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46, được sử dụng cùng nhau.
left if not left else right
1
keyword is used to specify that the block is intentionally left blank. It’s the equivalent of a no-op, or no operation. Here are a few examples of using
left if not left else right
1 to specify that the block is blank:

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
3

Từ khóa

left if not left else right
1

Vì Python không có các chỉ số khối để chỉ định kết thúc của một khối, từ khóa
left if not left else right
1 được sử dụng để chỉ định rằng khối bị bỏ trống một cách cố ý. Nó tương đương với không có hoạt động, hoặc không có hoạt động. Dưới đây là một vài ví dụ về việc sử dụng
left if not left else right
1 để chỉ định rằng khối trống:

Để biết thêm về

left if not left else right
1, hãy xem câu lệnh PASS: Làm thế nào để không làm gì trong Python.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48
keyword is used to define a function that doesn’t have a name and has only one statement, the results of which are returned. Functions defined with
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 are referred to as lambda functions:

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
4

Một ví dụ cơ bản về hàm

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 tính toán đối số được đưa ra cho sức mạnh của
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
82 sẽ trông như thế này:

Điều này tương đương với việc xác định chức năng với

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43:

Một cách sử dụng phổ biến cho hàm

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 là chỉ định một hành vi khác cho một hàm khác. Ví dụ, hãy tưởng tượng bạn muốn sắp xếp một danh sách các chuỗi theo các giá trị số nguyên của chúng. Hành vi mặc định của
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
85 sẽ sắp xếp các chuỗi theo thứ tự bảng chữ cái. Nhưng với
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
85, bạn có thể chỉ định danh sách nào nên được sắp xếp.

Chức năng Lambda cung cấp một cách tốt đẹp để làm như vậy:

>>>

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
5

Ví dụ này sắp xếp danh sách không dựa trên thứ tự bảng chữ cái mà theo thứ tự số của các ký tự cuối cùng của các chuỗi sau khi chuyển đổi chúng thành số nguyên. Không có

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, bạn sẽ phải xác định một hàm, đặt tên cho nó và sau đó chuyển nó sang
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
85.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 làm cho mã này sạch hơn.

Để so sánh, đây là những gì ví dụ trên sẽ trông như thế nào nếu không sử dụng

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48:

>>>

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
6

Ví dụ này sắp xếp danh sách không dựa trên thứ tự bảng chữ cái mà theo thứ tự số của các ký tự cuối cùng của các chuỗi sau khi chuyển đổi chúng thành số nguyên. Không có

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, bạn sẽ phải xác định một hàm, đặt tên cho nó và sau đó chuyển nó sang
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
85.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 làm cho mã này sạch hơn.

Để so sánh, đây là những gì ví dụ trên sẽ trông như thế nào nếu không sử dụng

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48:

Mã này tạo ra kết quả tương tự như ví dụ >>> import keyword >>> keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'async', ... >>> len(keyword.kwlist) 35 48, nhưng bạn cần xác định chức năng trước khi sử dụng.

Để biết thêm thông tin về

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, hãy xem cách sử dụng các hàm Python Lambda.

Trả về từ khóa:
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43,
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94

Có hai từ khóa Python được sử dụng để chỉ định những gì được trả về từ các chức năng hoặc phương thức:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43 và
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94. Hiểu khi nào và ở đâu để sử dụng
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43 là rất quan trọng để trở thành một lập trình viên Python tốt hơn. Từ khóa
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94 là một tính năng nâng cao hơn của Python, nhưng nó cũng có thể là một công cụ hữu ích để hiểu.
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43
keyword is valid only as part of a function defined with
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43. When Python encounters this keyword, it will exit the function at that point and return the results of whatever comes after the
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43 keyword:

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
7

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43

>>>

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
8

Ví dụ này sắp xếp danh sách không dựa trên thứ tự bảng chữ cái mà theo thứ tự số của các ký tự cuối cùng của các chuỗi sau khi chuyển đổi chúng thành số nguyên. Không có

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, bạn sẽ phải xác định một hàm, đặt tên cho nó và sau đó chuyển nó sang
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
85.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 làm cho mã này sạch hơn.

>>>

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
9

Ví dụ này sắp xếp danh sách không dựa trên thứ tự bảng chữ cái mà theo thứ tự số của các ký tự cuối cùng của các chuỗi sau khi chuyển đổi chúng thành số nguyên. Không có

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, bạn sẽ phải xác định một hàm, đặt tên cho nó và sau đó chuyển nó sang
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
85.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 làm cho mã này sạch hơn.

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
0

Để so sánh, đây là những gì ví dụ trên sẽ trông như thế nào nếu không sử dụng

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48:

Mã này tạo ra kết quả tương tự như ví dụ

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, nhưng bạn cần xác định chức năng trước khi sử dụng.

Để biết thêm thông tin về
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, hãy xem cách sử dụng các hàm Python Lambda.

Trả về từ khóa:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43,
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94
keyword is kind of like the
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43 keyword in that it specifies what gets returned from a function. However, when a function has a
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94 statement, what gets returned is a generator. The generator can then be passed to Python’s built-in
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
12 to get the next value returned from the function.

Có hai từ khóa Python được sử dụng để chỉ định những gì được trả về từ các chức năng hoặc phương thức:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43 và
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94. Hiểu khi nào và ở đâu để sử dụng
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43 là rất quan trọng để trở thành một lập trình viên Python tốt hơn. Từ khóa
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94 là một tính năng nâng cao hơn của Python, nhưng nó cũng có thể là một công cụ hữu ích để hiểu.

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
1

Từ khóa

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43

>>>

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
2

Ví dụ này sắp xếp danh sách không dựa trên thứ tự bảng chữ cái mà theo thứ tự số của các ký tự cuối cùng của các chuỗi sau khi chuyển đổi chúng thành số nguyên. Không có

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, bạn sẽ phải xác định một hàm, đặt tên cho nó và sau đó chuyển nó sang
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
85.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48 làm cho mã này sạch hơn.

Để so sánh, đây là những gì ví dụ trên sẽ trông như thế nào nếu không sử dụng

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48:

Mã này tạo ra kết quả tương tự như ví dụ >>> import keyword >>> keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'async', ... >>> len(keyword.kwlist) 35 48, nhưng bạn cần xác định chức năng trước khi sử dụng.

Để biết thêm thông tin về

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
48, hãy xem cách sử dụng các hàm Python Lambda.

Trả về từ khóa:

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
43,
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
94

Từ khóa
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20

Từ khóa Python từ

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20 được sử dụng để nhập hoặc bao gồm một mô -đun để sử dụng trong chương trình Python của bạn. Cú pháp sử dụng cơ bản trông như thế này:

Sau khi tuyên bố đó chạy,

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
25 sẽ có sẵn cho chương trình của bạn.

Ví dụ: nếu bạn muốn sử dụng lớp

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 từ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 trong thư viện tiêu chuẩn, thì bạn có thể sử dụng mã sau:

>>>

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
3

Nhập

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 theo cách này tạo ra toàn bộ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27, bao gồm cả lớp
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26, có sẵn cho chương trình của bạn. Bằng cách sử dụng tên mô -đun, bạn có quyền truy cập vào tất cả các công cụ có sẵn trong mô -đun đó. Để có quyền truy cập vào
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26, bạn tham khảo nó từ mô -đun:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
32.

Từ khóa
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21

Từ khóa

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21 được sử dụng cùng với
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20 để nhập một cái gì đó cụ thể từ một mô -đun:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21
keyword is used together with
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20 to import something specific from a module:

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
4

Điều này sẽ nhập bất cứ thứ gì

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
36 nằm trong
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
25 để được sử dụng trong chương trình của bạn. Hai từ khóa Python này,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21 và
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20, được sử dụng cùng nhau.

Nếu bạn muốn sử dụng

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 từ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 trong thư viện tiêu chuẩn, thì bạn có thể nhập cụ thể:

>>>

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
5

Nhập

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 theo cách này tạo ra toàn bộ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27, bao gồm cả lớp
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26, có sẵn cho chương trình của bạn. Bằng cách sử dụng tên mô -đun, bạn có quyền truy cập vào tất cả các công cụ có sẵn trong mô -đun đó. Để có quyền truy cập vào
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26, bạn tham khảo nó từ mô -đun:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
32.

Từ khóa
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21

Từ khóa

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21 được sử dụng cùng với
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20 để nhập một cái gì đó cụ thể từ một mô -đun:
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46
keyword is used to alias an imported module or tool. It’s used together with the Python keywords
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20 and
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21 to change the name of the thing being imported:

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
6

Điều này sẽ nhập bất cứ thứ gì

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
36 nằm trong
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
25 để được sử dụng trong chương trình của bạn. Hai từ khóa Python này,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21 và
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20, được sử dụng cùng nhau.

Nếu bạn muốn sử dụng

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 từ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 trong thư viện tiêu chuẩn, thì bạn có thể nhập cụ thể:

>>>

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
7

Nhập

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 theo cách này tạo ra toàn bộ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27, bao gồm cả lớp
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26, có sẵn cho chương trình của bạn. Bằng cách sử dụng tên mô -đun, bạn có quyền truy cập vào tất cả các công cụ có sẵn trong mô -đun đó. Để có quyền truy cập vào
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26, bạn tham khảo nó từ mô -đun:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
32.

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
8

Từ khóa

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21

Từ khóa >>> x = True >>> x is True True >>> y = False >>> y is False True 21 được sử dụng cùng với >>> x = True >>> x is True True >>> y = False >>> y is False True 20 để nhập một cái gì đó cụ thể từ một mô -đun:

Điều này sẽ nhập bất cứ thứ gì

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
36 nằm trong
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
25 để được sử dụng trong chương trình của bạn. Hai từ khóa Python này,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21 và
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20, được sử dụng cùng nhau.

Nếu bạn muốn sử dụng

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 từ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 trong thư viện tiêu chuẩn, thì bạn có thể nhập cụ thể:

Nhập
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 như thế này làm cho lớp
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 có sẵn, nhưng không có gì khác từ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27 có sẵn.
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 hiện có sẵn mà không cần bạn phải tham khảo nó từ mô -đun
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
27.

Từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57
keyword. This is the same in most other programming languages that have exception handling.

Từ khóa

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46 được sử dụng để bí danh một mô -đun hoặc công cụ đã nhập. Nó được sử dụng cùng với các từ khóa Python
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
20 và
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
21 để thay đổi tên của thứ đang được nhập:

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
9

Đối với các mô -đun có tên thực sự dài hoặc bí danh nhập khẩu thường được sử dụng,

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46 có thể hữu ích trong việc tạo bí danh.

Nếu bạn muốn nhập lớp

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 từ mô -đun bộ sưu tập nhưng đặt tên cho nó là một cái gì đó khác biệt, bạn có thể bí danh bằng cách sử dụng
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
0

Bây giờ

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
26 có sẵn để được sử dụng trong chương trình của bạn, nhưng nó được tham chiếu bởi
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
55 thay thế. Một cách sử dụng phổ biến hơn của
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46 Bí danh nhập khẩu là với các gói Numpy hoặc Pandas. Chúng thường được nhập khẩu bí danh tiêu chuẩn:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
1

Đây là một giải pháp thay thế tốt hơn để chỉ nhập mọi thứ từ một mô -đun và nó cho phép bạn rút ngắn tên của mô -đun đang được nhập.

Từ khóa xử lý ngoại lệ:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
59,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60,
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62

Một trong những khía cạnh phổ biến nhất của bất kỳ chương trình Python nào là việc nâng cao và bắt các trường hợp ngoại lệ. Bởi vì đây là một khía cạnh cơ bản của tất cả các mã Python, có một số từ khóa Python có sẵn để giúp làm cho phần này của mã của bạn rõ ràng và súc tích.

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 keyword is used with
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 to define what to do when specific exceptions are raised. You can have one or more
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 blocks with a single
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57. The basic usage looks like this:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
2

Các phần dưới đây đi qua các từ khóa Python này và cách sử dụng cơ bản của chúng. Đối với một hướng dẫn chuyên sâu hơn về các từ khóa này, hãy xem các ngoại lệ của Python: Giới thiệu.

>>>

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
3

Bạn có thể sửa đổi

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
78 và sử dụng nhiều khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 để xử lý tình huống này:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
4

Tại đây, bạn sửa đổi

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
78 để nâng ngoại lệ
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
91 chỉ sau khi bạn đã in một lời nhắc hữu ích lên màn hình.

Lưu ý rằng từ khóa

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 cũng có thể được sử dụng cùng với từ khóa
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46. Điều này có tác dụng tương tự như các cách sử dụng khác của
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
46, mang lại cho ngoại lệ được nâng cao một bí danh để bạn có thể làm việc với nó trong khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58.

Mặc dù nó được phép về mặt cú pháp, nhưng hãy cố gắng không sử dụng các câu lệnh

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 như những điều hấp dẫn ngầm. Nó thực hành tốt hơn để luôn luôn bắt được một cái gì đó một cách rõ ràng, ngay cả khi nó chỉ là
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
97:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
5

Nếu bạn thực sự muốn bắt một loạt các ngoại lệ, thì hãy chỉ định cha mẹ

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
97. Đây rõ ràng hơn là một Catchall, và nó đã giành được các trường hợp ngoại lệ mà bạn có thể không muốn bắt, như
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
99 hoặc
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
00.

Từ khóa
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
59

Từ khóa

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
59 làm tăng một ngoại lệ. Nếu bạn thấy bạn cần phải tăng một ngoại lệ, thì bạn có thể sử dụng
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
59 theo sau là ngoại lệ để được nâng lên:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
59
keyword raises an exception. If you find you need to raise an exception, then you can use
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
59 followed by the exception to be raised:

Bạn đã sử dụng

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
59 trước đây, trong ví dụ
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
78. Khi bạn bắt được
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
91, bạn sẽ ghi lại ngoại lệ sau khi in tin nhắn lên màn hình.

Từ khóa
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60

Từ khóa Python từ

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60 rất hữu ích cho việc chỉ định mã sẽ được chạy bất kể điều gì xảy ra trong các khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 hoặc
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29. Để sử dụng
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60, hãy sử dụng nó như một phần của khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 và chỉ định các câu lệnh nên được chạy bất kể điều gì:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60
keyword is helpful for specifying code that should be run no matter what happens in the
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57,
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58, or
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 blocks. To use
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60, use it as part of a
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 block and specify the statements that should be run no matter what:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
6

Sử dụng ví dụ từ trước, có thể hữu ích để chỉ định rằng, bất kể điều gì xảy ra, bạn muốn biết những đối số nào chức năng được gọi với. Bạn có thể sửa đổi

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
78 để bao gồm một khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60 chỉ làm điều đó:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
7

Bây giờ, cho dù

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
78 được gọi là gì hoặc kết quả là gì, bạn in các đối số do người dùng cung cấp:

>>>

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
8

Từ khóa

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
60 có thể là một phần rất hữu ích trong mã xử lý ngoại lệ của bạn.

Từ khóa
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 được sử dụng với
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 và
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58

Bạn đã học được rằng từ khóa

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 có thể được sử dụng với cả từ khóa và vòng lặp
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 trong Python, nhưng nó có thêm một lần sử dụng. Nó có thể được kết hợp với các từ khóa Python
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 và
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58. Bạn chỉ có thể sử dụng
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 theo cách này nếu bạn cũng sử dụng ít nhất một khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58:
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29
keyword can be used with both the
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
74 keyword and loops in Python, but it has one more use. It can be combined with the
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 and
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 Python keywords. You can use
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 in this way only if you also use at least one
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58 block:

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
9

Trong bối cảnh này, mã trong khối

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 chỉ được thực thi nếu một ngoại lệ không được nêu trong khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57. Nói cách khác, nếu khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 thực hiện tất cả mã thành công, thì mã khối
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 sẽ được thực thi.

Trong ví dụ

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
78, hãy tưởng tượng bạn muốn đảm bảo rằng kết quả
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
72 luôn được trả lại dưới dạng
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
33 bất kể sự kết hợp số nào được thông qua. Một trong những cách bạn có thể làm điều này là sử dụng khối ____229. Nếu tính toán khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 của
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
72 thành công, thì bạn sẽ chuyển đổi kết quả thành
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
33 trong khối
>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 trước khi quay lại:

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
0

Bây giờ kết quả của một cuộc gọi đến

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
78, nếu thành công, sẽ luôn luôn là
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
33.

Để biết thêm về việc sử dụng khối

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation — when it is executed, nothing happens. It
is useful as a placeholder when a statement is required syntactically,
but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)
29 như một phần của khối
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
57 và
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
58, hãy xem các ngoại lệ Python: Giới thiệu.

Từ khóa
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62

Từ khóa

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 trong Python được sử dụng để chỉ định câu lệnh
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 hoặc khẳng định về biểu thức. Một tuyên bố
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 sẽ dẫn đến không có gì nếu biểu thức (
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
48) là sự thật và nó sẽ tăng
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
49 nếu biểu thức là giả. Để xác định khẳng định, hãy sử dụng
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 theo sau là biểu thức:
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62
keyword in Python is used to specify an
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 statement, or an assertion about an expression. An
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 statement will result in a no-op if the expression (
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
48) is truthy, and it will raise an
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
49 if the expression is falsy. To define an assertion, use
>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 followed by an expression:

Nói chung, các câu lệnh

>>> x = True
>>> x is True
True

>>> y = False
>>> y is False
True
62 sẽ được sử dụng để đảm bảo một cái gì đó cần phải đúng. Tuy nhiên, bạn không nên dựa vào họ, vì chúng có thể bị bỏ qua tùy thuộc vào cách thực thi chương trình Python của bạn.

Từ khóa lập trình không đồng bộ: >>> def func(): ... print("hello") ... >>> x = func() hello >>> print(x) None 6, >>> def func(): ... print("hello") ... >>> x = func() hello >>> print(x) None 5

Lập trình không đồng bộ là một chủ đề phức tạp. Có hai từ khóa Python được xác định để giúp làm cho mã không đồng bộ trở nên dễ đọc hơn và sạch hơn:

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 và
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
5.

Các phần dưới đây giới thiệu hai từ khóa không đồng bộ và cú pháp cơ bản của chúng, nhưng họ đã giành được chiều sâu về lập trình không đồng bộ. Để tìm hiểu thêm về lập trình không đồng bộ, hãy xem Async IO trong Python: một hướng dẫn hoàn chỉnh và bắt đầu với các tính năng Async trong Python.

Từ khóa
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6

Từ khóa

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 được sử dụng với
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43 để xác định hàm không đồng bộ hoặc coroutine. Cú pháp giống như xác định một hàm, với việc bổ sung
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 ở đầu:
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6
keyword is used with
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', ...
>>> len(keyword.kwlist)
35
43 to define an asynchronous function, or coroutine. The syntax is just like defining a function, with the addition of
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 at the beginning:

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
1

Bạn có thể tạo một chức năng không đồng bộ bằng cách thêm từ khóa

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 trước khi định nghĩa thông thường của hàm.

Từ khóa
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
5

Từ khóa Python từ ____ ____75 được sử dụng trong các chức năng không đồng bộ để chỉ định một điểm trong hàm nơi điều khiển được đưa trở lại vòng lặp sự kiện để các chức năng khác chạy. Bạn có thể sử dụng nó bằng cách đặt từ khóa

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
5 trước cuộc gọi đến bất kỳ chức năng
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 nào:
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
5
keyword is used in asynchronous functions to specify a point in the function where control is given back to the event loop for other functions to run. You can use it by placing the
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
5 keyword in front of a call to any
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
6 function:

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
2

Khi sử dụng

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
5, bạn có thể gọi hàm không đồng bộ và bỏ qua kết quả hoặc bạn có thể lưu trữ kết quả trong một biến khi cuối cùng hàm trở lại.

Từ khóa xử lý biến: >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 66, >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 67, >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 68

Ba từ khóa Python được sử dụng để làm việc với các biến. Từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
66 được sử dụng phổ biến hơn nhiều so với từ khóa
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67 và
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
68. Nhưng nó vẫn hữu ích để biết và hiểu cả ba từ khóa để bạn có thể xác định khi nào và cách sử dụng chúng.

Từ khóa
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
66

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
66 được sử dụng trong Python để không đặt một biến hoặc tên. Bạn có thể sử dụng nó trên các tên biến, nhưng sử dụng phổ biến hơn là xóa các chỉ mục khỏi danh sách hoặc từ điển. Để giải quyết một biến, hãy sử dụng
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
66 theo sau là biến bạn muốn giải quyết:
is used in Python to unset a variable or name. You can use it on variable names, but a more common use is to remove indexes from a list or dictionary. To unset a variable, use
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
66 followed by the variable you want to unset:

Hãy giả sử bạn muốn làm sạch một từ điển mà bạn nhận được từ một phản hồi API bằng cách ném ra các phím mà bạn biết bạn đã giành được sử dụng. Bạn có thể làm như vậy với từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
66:

>>>

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
3

Điều này sẽ loại bỏ các khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
76 và
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
77 khỏi từ điển
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
78.

Từ khóa
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67

Nếu bạn cần sửa đổi một biến được xác định trong một hàm nhưng được xác định trong phạm vi toàn cầu, thì bạn sẽ cần sử dụng từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67. Điều này hoạt động bằng cách chỉ định trong hàm mà các biến cần được kéo vào hàm từ phạm vi toàn cầu:global scope, then you’ll need to use the
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67
keyword. This works by specifying in the function which variables need to be pulled into the function from the global scope:

Một ví dụ cơ bản là tăng một biến toàn cầu với một cuộc gọi chức năng. Bạn có thể làm điều đó với từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67:

>>>

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
4

Điều này sẽ loại bỏ các khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
76 và
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
77 khỏi từ điển
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
78.

Từ khóa
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67

Nếu bạn cần sửa đổi một biến được xác định trong một hàm nhưng được xác định trong phạm vi toàn cầu, thì bạn sẽ cần sử dụng từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67. Điều này hoạt động bằng cách chỉ định trong hàm mà các biến cần được kéo vào hàm từ phạm vi toàn cầu:
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
68
keyword is similar to
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67 in that it allows you to modify variables from a different scope. With
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67, the scope you’re pulling from is the global scope. With
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
68, the scope you’re pulling from is the parent scope. The syntax is similar to
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67:

Một ví dụ cơ bản là tăng một biến toàn cầu với một cuộc gọi chức năng. Bạn có thể làm điều đó với từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67:

Điều này thường không được coi là thực hành tốt, nhưng nó có cách sử dụng của nó. Để tìm hiểu thêm về từ khóa >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 67, hãy xem Python Phạm vi & Quy tắc LegB: Giải quyết tên trong mã của bạn.

Từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
68

Từ khóa >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 68 tương tự như >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 67 ở chỗ nó cho phép bạn sửa đổi các biến từ một phạm vi khác. Với >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 67, phạm vi mà bạn đã lấy từ là phạm vi toàn cầu. Với >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 68, phạm vi mà bạn kéo từ là phạm vi cha mẹ. Cú pháp tương tự như >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 67:

Từ khóa này được sử dụng rất thường xuyên, nhưng đôi khi nó có thể tiện dụng. Để biết thêm về phạm vi và từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
68, hãy xem phạm vi Python & Quy tắc LegB: Giải quyết tên trong mã của bạn.
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
7
was a keyword, the syntax to print something to the screen looked like this:

Từ khóa Python không dùng nữa

Đôi khi một từ khóa Python trở thành một hàm tích hợp. Đó là trường hợp với cả

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
7 và
>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
8. Chúng từng là từ khóa Python trong phiên bản 2.7, nhưng chúng đã được thay đổi thành các chức năng tích hợp.

Từ khóa

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
7 trước đây

Khi >>> def func(): ... print("hello") ... >>> x = func() hello >>> print(x) None 7 là một từ khóa, cú pháp để in một cái gì đó lên màn hình trông như thế này:

Lưu ý rằng nó trông giống như rất nhiều câu lệnh từ khóa khác, với từ khóa theo sau là các đối số.

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
8 keyword took Python code as a string and executed it. This was done with the following syntax:

Bây giờ

>>> def func():
...     print("hello")
...
>>> x = func()
hello
>>> print(x)
None
7 không còn là một từ khóa và việc in được thực hiện với
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
95 tích hợp. Để in một cái gì đó lên màn hình, bây giờ bạn sử dụng cú pháp sau:

>>>

>>> x = "this is a truthy value"
>>> if x is True:  # Don't do this
...     print("x is True")
...
>>> if x:  # Do this
...     print("x is truthy")
...
x is truthy
5

Điều này sẽ loại bỏ các khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
76 và
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
77 khỏi từ điển
>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
78.

Từ khóa >>> x = "this is a truthy value" >>> x is True False >>> bool(x) is True True >>> y = "" # This is falsy >>> y is False False >>> bool(y) is False True 67

Nếu bạn cần sửa đổi một biến được xác định trong một hàm nhưng được xác định trong phạm vi toàn cầu, thì bạn sẽ cần sử dụng từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67. Điều này hoạt động bằng cách chỉ định trong hàm mà các biến cần được kéo vào hàm từ phạm vi toàn cầu:

Một ví dụ cơ bản là tăng một biến toàn cầu với một cuộc gọi chức năng. Bạn có thể làm điều đó với từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67:

Điều này thường không được coi là thực hành tốt, nhưng nó có cách sử dụng của nó. Để tìm hiểu thêm về từ khóa

>>> x = "this is a truthy value"
>>> x is True
False
>>> bool(x) is True
True

>>> y = ""  # This is falsy
>>> y is False
False
>>> bool(y) is False
True
67, hãy xem Python Phạm vi & Quy tắc LegB: Giải quyết tên trong mã của bạn.

  • Từ khóa
    >>> x = "this is a truthy value"
    >>> x is True
    False
    >>> bool(x) is True
    True
    
    >>> y = ""  # This is falsy
    >>> y is False
    False
    >>> bool(y) is False
    True
    
    68Python keywords in version 3.8 and their basic usage
  • Từ khóa
    >>> x = "this is a truthy value"
    >>> x is True
    False
    >>> bool(x) is True
    True
    
    >>> y = ""  # This is falsy
    >>> y is False
    False
    >>> bool(y) is False
    True
    
    68 tương tự như
    >>> x = "this is a truthy value"
    >>> x is True
    False
    >>> bool(x) is True
    True
    
    >>> y = ""  # This is falsy
    >>> y is False
    False
    >>> bool(y) is False
    True
    
    67 ở chỗ nó cho phép bạn sửa đổi các biến từ một phạm vi khác. Với
    >>> x = "this is a truthy value"
    >>> x is True
    False
    >>> bool(x) is True
    True
    
    >>> y = ""  # This is falsy
    >>> y is False
    False
    >>> bool(y) is False
    True
    
    67, phạm vi mà bạn đã lấy từ là phạm vi toàn cầu. Với
    >>> x = "this is a truthy value"
    >>> x is True
    False
    >>> bool(x) is True
    True
    
    >>> y = ""  # This is falsy
    >>> y is False
    False
    >>> bool(y) is False
    True
    
    68, phạm vi mà bạn kéo từ là phạm vi cha mẹ. Cú pháp tương tự như
    >>> x = "this is a truthy value"
    >>> x is True
    False
    >>> bool(x) is True
    True
    
    >>> y = ""  # This is falsy
    >>> y is False
    False
    >>> bool(y) is False
    True
    
    67:resources to help deepen your understanding of many of the keywords
  • Từ khóa này được sử dụng rất thường xuyên, nhưng đôi khi nó có thể tiện dụng. Để biết thêm về phạm vi và từ khóa
    >>> x = "this is a truthy value"
    >>> x is True
    False
    >>> bool(x) is True
    True
    
    >>> y = ""  # This is falsy
    >>> y is False
    False
    >>> bool(y) is False
    True
    
    68, hãy xem phạm vi Python & Quy tắc LegB: Giải quyết tên trong mã của bạn.
    >>> def func():
    ...     print("hello")
    ...
    >>> x = func()
    hello
    >>> print(x)
    None
    
    2 module
    to work with keywords in a programmatic way

Từ khóa Python không dùng nữa

Xem bây giờ hướng dẫn này có một khóa học video liên quan được tạo bởi nhóm Python thực sự.Xem cùng với hướng dẫn bằng văn bản để hiểu sâu hơn về sự hiểu biết của bạn: Khám phá các từ khóa trong Python This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Exploring Keywords in Python