Trong hướng dẫn này, bạn sẽ tìm hiểu về các từ khóa (từ dành riêng trong Python) và số nhận dạng (tên được đặt cho các biến, hàm, v.v.). Show
Từ khóa PythonCác từ khóa được xác định trước, các từ dành riêng được sử dụng trong chương trình Python có ý nghĩa đặc biệt đối với trình biên dịch. Chúng tôi không thể sử dụng từ khóa làm tên biến, tên hàm hoặc bất kỳ định danh nào khác. Chúng được sử dụng để xác định cú pháp và cấu trúc của ngôn ngữ Python. Tất cả các từ khóa ngoại trừ 6, 7 và 8 đều bằng chữ thường và chúng phải được viết như chúng. Danh sách tất cả các từ khóa được đưa ra dưới đây.
given number is even3 Nhìn vào tất cả các từ khóa cùng một lúc và cố gắng tìm ra ý nghĩa của chúng có thể là quá sức. Nếu bạn muốn có một cái nhìn tổng quan, đây là danh sách đầy đủ của tất cả các từ khóa với các ví dụ.Định danh Python
Định danh là tên được đặt cho các biến, lớp, phương thức, v.v. Ở đây, given number is even4 là một biến (một định danh) chứa giá trị given number is even5.
Chúng tôi không thể sử dụng các từ khóa làm tên biến vì chúng được đặt tên được tích hợp cho Python. Ví dụ, Mã trên là sai vì chúng tôi đã sử dụng 1 2 3 4 55 làm tên biến. Để tìm hiểu thêm về các biến, hãy truy cập các biến Python.
Chúng ta không thể sử dụng các biểu tượng đặc biệt như!, @, #, $, V.v.
Chuyển đổi sang_StringNhững điều cần ghi nhớ Python là một ngôn ngữ nhạy cảm trường hợp. Điều này có nghĩa là, given number is even9 và 0.1 Exception raises None0 không giống nhau. Luôn luôn đặt cho các định danh một cái tên có ý nghĩa. Mặc dù 0.1 Exception raises None1 là một tên hợp lệ, viết 0.1 Exception raises None2 sẽ có ý nghĩa hơn và sẽ dễ dàng hơn để tìm ra những gì nó thể hiện khi bạn nhìn vào mã của mình sau một khoảng cách dài. Ví dụ 16: Sử dụng từ khóa & nbsp; are some predefined and reserved words in python that have special meanings. Keywords are used to define the syntax of the coding. The keyword cannot be used as an identifier, function, and variable name. All the keywords in python are written in lower case except True and False. There are 33 keywords in Python 3.7 let’s go through all of them one by one.
Biến Python là một tên biểu tượng là một tham chiếu hoặc con trỏ đến một đối tượng. Khi một đối tượng được gán cho một biến, bạn có thể tham khảo đối tượng bằng tên đó. Nhưng chính dữ liệu vẫn còn trong đối tượng.
Ví dụ 1: Ví dụ về và, hoặc không, đúng, từ khóa sai. Example of and, or, not, True, False keywords. Python0.1 Exception raises None4 0.1 Exception raises None5 0.1 Exception raises None6 0.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 6 given number is even2 70.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 One Two else block execute else block execute7 70.1 Exception raises None7 Output: example of True, False, and, or not keywords True True True Ví dụ 2: Ví dụ về nghỉ, tiếp tục. Example of a break, continue. Python0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 0.1 Exception raises None4 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']6 0.1 Exception raises None4 0.1 Exception raises None5 6 given number is even2 70.1 Exception raises None7 021 2 3 4 55 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 example of True, False, and, or not keywords True True True1 01 02example of True, False, and, or not keywords True True True5 Output: 1 2 3 4 5
Python0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 6 given number is even2 70.1 Exception raises None7 020.1 Exception raises None4 0.1 Exception raises None5 280.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 One Two else block execute else block execute7 70.1 Exception raises None7 020.1 Exception raises None4 0.1 Exception raises None5 400.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 example of True, False, and, or not keywords True True True1 24 020.1 Exception raises None4 0.1 Exception raises None5 480.1 Exception raises None7 Output: One Two else block execute else block execute Ví dụ 2: Ví dụ về nghỉ, tiếp tục. Example of def, if, and else keywords. Python0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 53 21 550.1 Exception raises None4 0.1 Exception raises None5 6 given number is even2 70.1 Exception raises None7 020.1 Exception raises None4 0.1 Exception raises None5 680.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 example of True, False, and, or not keywords True True True1 24 020.1 Exception raises None4 0.1 Exception raises None5 76 77 78Output: given number is even
Python0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 1 2 3 4 58 240.1 Exception raises None4 0.1 Exception raises None5 6 given number is even2 70.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 example of True, False, and, or not keywords True True True6 24 020.1 Exception raises None4 0.1 Exception raises None5 960.1 Exception raises None7 021 2 3 4 53 0.1 Exception raises None4 0.1 Exception raises None5 One Two else block execute else block execute7 70.1 Exception raises None7 0.1 Exception raises None4 example of True, False, and, or not keywords True True True04 example of True, False, and, or not keywords True True True05 example of True, False, and, or not keywords True True True06 0.1 Exception raises None4 example of True, False, and, or not keywords True True True04 63example of True, False, and, or not keywords True True True06 Output: 0.1 Exception raises None Ví dụ 2: Ví dụ về nghỉ, tiếp tục. Example of a lambda keyword. Python0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 6 given number is even2 70.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 0.1 Exception raises None4 example of True, False, and, or not keywords True True True28 Output: 2 3 4 5 6
Python0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 6 given number is even2 70.1 Exception raises None7 0.1 Exception raises None4 0.1 Exception raises None5 One Two else block execute else block execute7 70.1 Exception raises None7 Ví dụ 2: Ví dụ về nghỉ, tiếp tục. 0.1 Exception raises None4 example of True, False, and, or not keywords True True True42 Output: 5
Python0.1 Exception raises None4 0.1 Exception raises None5 6 1 2 3 4 54 60.1 Exception raises None7 0.1 Exception raises None4 example of True, False, and, or not keywords True True True57 One Two else block execute else block execute5 example of True, False, and, or not keywords True True True59 35example of True, False, and, or not keywords True True True55 0.1 Exception raises None4 example of True, False, and, or not keywords True True True57 Output: ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e'] Ví dụ 9: Sử dụng từ khóa toàn cầu.: use of global keyword. Pythonexample of True, False, and, or not keywords True True True64 21 example of True, False, and, or not keywords True True True05 One Two else block execute else block execute0 example of True, False, and, or not keywords True True True68 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 0.1 Exception raises None4 example of True, False, and, or not keywords True True True71 One Two else block execute else block execute0 example of True, False, and, or not keywords True True True73 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 One Two else block execute else block execute6 example of True, False, and, or not keywords True True True76 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 example of True, False, and, or not keywords True True True64 21 example of True, False, and, or not keywords True True True80 example of True, False, and, or not keywords True True True81 example of True, False, and, or not keywords True True True82 Output: 0Ví dụ 10: Ví dụ về từ khóa năng suất. example of yield keyword. Pythonexample of True, False, and, or not keywords True True True64 21 example of True, False, and, or not keywords True True True05 One Two else block execute else block execute0 example of True, False, and, or not keywords True True True68 One Two else block execute else block execute0 example of True, False, and, or not keywords True True True73 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 One Two else block execute else block execute6 example of True, False, and, or not keywords True True True76 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 example of True, False, and, or not keywords True True True64 21 example of True, False, and, or not keywords True True True80 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 0.1 Exception raises None4 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']6 Output: 1Ví dụ 10: Ví dụ về từ khóa năng suất. Use of assert keyword. Python3One Two else block execute else block execute0 example of True, False, and, or not keywords True True True84 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 1 2 3 4 56 56 example of True, False, and, or not keywords True True True7 58 0.1 Exception raises None5 example of True, False, and, or not keywords True True True24 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']3 02given number is even3 53example of True, False, and, or not keywords True True True15 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']0 10 21 1 2 3 4 500 0.1 Exception raises None4 0.1 Exception raises None5 1 2 3 4 527 1 2 3 4 528 Output: 2
Python3Ví dụ 11: Sử dụng từ khóa Assert. Use of finally keyword Python3One Two else block execute else block execute0 1 2 3 4 509 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 1 2 3 4 58 24['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 One Two else block execute else block execute4 1 2 3 4 512 1 2 3 4 513 21 631 2 3 4 516 1 2 3 4 517 020.1 Exception raises None4 0.1 Exception raises None5 1 2 3 4 543 0.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 example of True, False, and, or not keywords True True True6 24 020.1 Exception raises None4 0.1 Exception raises None5 1 2 3 4 551 0.1 Exception raises None7 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 1 2 3 4 53 1 2 3 4 520 1 2 3 4 521 020.1 Exception raises None4 0.1 Exception raises None5 1 2 3 4 559 0.1 Exception raises None7 1 2 3 4 561 1 2 3 4 562 1 2 3 4 516 350.1 Exception raises None7 1 2 3 4 561 1 2 3 4 562 1 2 3 4 516 630.1 Exception raises None7
3Ví dụ 12: Sử dụng từ khóa vượt quaUse of import keyword Python3Ví dụ 13: Sử dụng từ khóa cuối cùng & nbsp; 0.1 Exception raises None4 0.1 Exception raises None5 1 2 3 4 575 1 2 3 4 576 00example of True, False, and, or not keywords True True True06
4Ví dụ 12: Sử dụng từ khóa vượt qua Use of is keyword Python3Ví dụ 13: Sử dụng từ khóa cuối cùng & nbsp; One Two else block execute else block execute0 1 2 3 4 530 021 2 3 4 535 21 example of True, False, and, or not keywords True True True37 881 2 3 4 539 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']4 1 2 3 4 51 24Đầu ra Ví dụ 14: Sử dụng từ khóa nhập khẩuUse of from keyword Python3example of True, False, and, or not keywords True True True2 1 2 3 4 572 0.1 Exception raises None4 0.1 Exception raises None5 One Two else block execute else block execute02 One Two else block execute else block execute03 One Two else block execute else block execute04 ['a', 'b', 'c', 'd', 'e'] ['a', 'b', 'd', 'e']1 One Two else block execute else block execute06 example of True, False, and, or not keywords True True True06
5Định danh từ khóa và biến là gì?Một số ngôn ngữ lập trình chứa các từ khóa và số nhận dạng được trình biên dịch nhận ra. Nói chung, các từ khóa là các từ dành riêng được xác định trước và cụ thể, có ý nghĩa đặc biệt. Mặt khác, một định danh là một thuật ngữ hoặc tên khác được đặt cho một biến, nhãn của lớp trong chương trình hoặc hàm.
Các biến trong Python là gì?Biến Python là một tên biểu tượng là một tham chiếu hoặc con trỏ đến một đối tượng.Khi một đối tượng được gán cho một biến, bạn có thể tham khảo đối tượng bằng tên đó.Nhưng chính dữ liệu vẫn còn trong đối tượng.a symbolic name that is a reference or pointer to an object. Once an object is assigned to a variable, you can refer to the object by that name. But the data itself is still contained within the object.
Định danh Python là gì?Định danh Python là gì?Định danh Python là tên chúng tôi đặt để xác định một biến, chức năng, lớp, mô -đun hoặc đối tượng khác.Điều đó có nghĩa là bất cứ khi nào chúng ta muốn đặt tên cho một thực thể, đó được gọi là định danh.Đôi khi biến đổi và định danh thường bị hiểu lầm là giống nhau nhưng chúng không.the name we give to identify a variable, function, class, module or other object. That means whenever we want to give an entity a name, that's called identifier. Sometimes variable and identifier are often misunderstood as same but they are not.
Các biến và số nhận dạng trong Python Các quy tắc định danh trong Python là gì?Tên định danh trong Python có thể chứa các số (0-9), chữ hoa (A-Z), chữ thường (A-Z) và nhấn mạnh (_).Tên phải luôn luôn bắt đầu với một ký tự không phải là số.Một tên định danh không chỉ chứa các ký tự số.Tên định danh trong Python nhạy cảm trường hợp như hầu hết các ngôn ngữ khác. |