(8)基本用法

it2022-05-05  107

基本用法

标识符:用于变量、函数、类、模块等的名称。具体的规则为:

区分大小写;第一个字母必须是字母、下划线。其后字符是:字母、数字、下划线。不能使用关键字;以双下划线开头和结尾的名称通常有特殊含义,尽量避免这种使用方法。

使用python的帮助系统可以查看关键字:

>>> help() Welcome to Python 3.7's help utility! If this is your first time using Python, you should definitely check out the tutorial on the Internet at https://docs.python.org/3.7/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, symbols, or topics, type "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", type "modules spam". 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 help>

举例

>>> sxt=123 >>> _sxt=456 >>> 3sdf=33 SyntaxError: invalid syntax >>>

Tips:

按”F1“可以打开python的官方文档;

python标识符命名规则

类型规则例子模块和包名全小写字母,尽量简单,若多个单词之间用下划线math,os,sys函数名全小写字母,多个单词之间用下划线隔开phone,my_name类名首字母大写,采用驼峰命名原则,多个单词时,每个单词第一个字母大写,其余部分小写MyPhone,MyClass,Phone常量名全大写字母,多个单词使用下划线隔开SPEED,MAX_SPEED

最新回复(0)