#注意字母大小写 #英文标点符号 print("Hello World")
Hello World
#如何寻求帮助
#利用系统的帮助文件 help(print)
Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.
#注释
#Python入门语言 print("Hello World") """ 多行注释 代码目的 代码解释 """
Hello World
'n多行注释n代码目的n代码解释n'
#变量
#定义变量 #变量定义三部曲:变量名+赋值符+值或表达式 a = 100 #将变量a的值显示在屏幕上 print(a) b = 100 * 100 print(b) print(B)
100 1000 --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-10-286252cc0e35> in <module>() 6 b = 100 * 100 7 print(b) ----> 8 print(B) NameError: name 'B' is not defined
#变量命名规则
#查询关键字 #导入相关包 import keyword #打印关键字 print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global',
'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return',
'try', 'while', 'with', 'yield']
#变量声明
a = 100 print(a) a = b = 100 #从右向左赋值 print(a, b) a, b, c = 1, 2, 3 #变量名与值意义对应 #错误的定义方式 a, b, c = 1, 2, 3, 4
100 100 100 1 2 3 --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-17-9f47cf12b0d3> in <module>() 5 a, b, c = 1, 2, 3 6 print(a, b, c) ----> 7 a, b, c = 1, 2, 3, 4 ValueError: too many values to unpack (expected 3)
参与评论
手机查看
返回顶部