程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[python learning 3] reserved words, identifiers, variables

編輯:Python

(1) reserved words in python

Reserved words are words that have been assigned specific meanings in python. When writing programs, You cannot use reserved words as the names of variables, functions, classes, modules and other objects

Reserved words in python:

andasassertbreakclasscontinuedefdelelifelseexceptfinallyforfromFalseglobalifimportinislambdanonlocalnotNoneorpassraisereturntryTruewhilewithyieldasyncawait

Reserved words are strictly case-sensitive, for example: true and True are not the same variable

Reserved words can also be viewed through program output:

import keywordprint(keyword.kwlist)

The program can directly output reserved words

(2) Identifier

Identifiers: Names used primarily to identify variables, functions, classes, modules, and other objects

Naming rules for python identifiers:

①Can be letters, underscores "_" and numbers, and the first character cannot be a number

②Cannot use reserved words in python

③Identifiers are strictly case-sensitive

④Identifiers starting with an underscore have special meanings, and similar identifiers should generally be avoided

Identifier naming convention:

①The module name should be as short as possible, and use all lowercase letters. You can use underscores to separate multiple letters.Such as grame_main.The module is the name of each python file

2 The package name should be as short as possible, and use all lowercase letters. Underscores are not recommended.Such as: com.bjmsb, com_bjmsb is not recommended. The package is the name of the python package file

③The class name should be capitalized with the first letter of the word (Pascal style).Such as MyClass

④The class inside the module is composed of "_" + Pascal style class name, such as the inner class _InnerMyClass in the MyClass class

⑤Name the properties and methods of functions, classes, use all lowercase letters, and use underscores to separate multiple letters

(3) Definition and use of variables

 

Dynamically typed languages: You can change the data type of a variable by assigning values ​​of different types

type(variable): You can view the data type of the variable

id (variable): You can view the memory address pointed to by the variable


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved