标识符

  • 第一个字符必须是字母或下划线
  • 标识符的其他的部分由字母、数字和下划线组成
  • 标识符对大小写敏感

Python保留字

即关键字,不能把它们用作任何标识符名称

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', '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']

多行语句

Python通常一行写完一条语句,但如果语句过长,我们可以使用反斜杠来实现多行语句

total = 'item_one' + \
    'item_two' + \
    'item_three'

同一行显示多条语句

Python可以在同一行中使用多条语句,语句之间使用分号(;)分割

total = 'item_one' + \
    'item_two' + \
    'item_three';print(total)

输出

用 print() 在括号中加上字符串,就可以向屏幕输入指定的文字。同时print()函数也可以接受多个字符串,采用逗号隔开的方式就可以连成一串输出(遇到逗号会输出一个空格)。

print('Hello world!')
print('Hi,', 'what is your name?', 'Bye!')

关键字end可以用于将结果输出到同一行,或者在输出的末尾添加不同的字符

print(str, end = ',')
print(str, end = ' ')

输入

input()函数可以让用户输入字符串,并存放到一个变量里。

name = input()
age = input('How old are you?')
print(name, 'is', age, 'years old!')
posted on 2018-09-26 11:08  Q同码  阅读(373)  评论(0编辑  收藏  举报