python笔记4-术语说明:标识符
基本用法
标识符:用于变量、函数、类、模块等的名称。
常规命名规则:
-
严格区分大小写,如:5x 和 SXT 是不同的
-
第一个字符必须是字母、下划线。其后的字符是:字母、数字、下划线
-
不能使用关键字。比如:if、or、 while等
-
不能使用特殊字符。比如:空格、@、% 以及 $ 等
-
以双下划线开头和结尾的名称通常有特殊含义,尽量避免这种写法。比如:__init__是类的构造函数。
开发中,约定俗成的命名规则:
| 类型 | 规则 | 例子 |
|---|---|---|
| 模块和包名 | 全小写字母,尽量简单。若多个单词之间用下划线 | math、os、sys |
| 函数名 | 全小写字母。若多个单词之间用下划线 | phone、my_name |
| 类名 | 首字母大写,采用驼峰原则。多个单词时每个单词第一个字母大写,其余部分小写 | MyPhone、MyName |
| 常量名 | 全大写字母,多个单词使用下划线隔开 | SPEED、MAX_SPEED |
使用python帮助系统查看关键字
>>> help()
help> keywords
Here is a list of the Python keywords. Enter any keyword to get more help.
False def if raise
None del import return
True elif in try
and else is while
as except lambda with
assert finally nonlocal yield
break for not
class from or
continue global pass
help> if
The "if" statement
******************
The "if" statement is used for conditional execution:
if_stmt ::= "if" expression ":" suite
( "elif" expression ":" suite )*
["else" ":" suite]
It selects exactly one of the suites by evaluating the expressions one
by one until one is found to be true (see section Boolean operations
for the definition of true and false); then that suite is executed
(and no other part of the "if" statement is executed or evaluated).
If all expressions are false, the suite of the "else" clause, if
present, is executed.
Related help topics: TRUTHVALUE

浙公网安备 33010602011771号