学习python的第二天之命名规则和print&input语句
标识符和关键字
标识符:变量,模块,函数名,类名
标识符的命名规则与规范:
规则:
由数字、数字和_组成,不能以数字开头;
严格区分大小写(计算机编程语言里,一共有52英语字母);
不能使用关键字(在Python语言里,有特殊含义的词)
关键字,例如:if/for/else/while/try/True/False等等…
规范:
- 顾名思义;
- 遵守一定的命名规则;
- 小驼峰命名法:第一个单词的首字母小写,以后每个单词的首字母都大写 userNameAndPassword
- 大驼峰命名法:每个单词的首字母都大写 PersonModel
- 使用下划线连接:user_name_and_password
- 在Python里的变量、函数和模块名使用下划线连接;Python里的类名使用大驼峰命名法。
print语句的使用
使用print内置函数来输出内容(打印在屏幕上)
print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
sep 参数用来表示输出时,每个值之间使用哪种字符作为分隔。默认使用空格作为分隔符;
end 当执行完一个print语句以后,接下来要输出的字符。默认\n表示换行;
print('hello', 'good', 'yes', 'oh') #--> hello good yes oh (每个词之间以空格连接)
print('hello', 'good', 'yes', 'oh', sep='+') #--> hello+good+yes+oh (每个词之间以+连接)
print('Hello', end='$$$$$$$$$$$$$')
print('World')
#--> Hello$$$$$$$$$$$$$World
input语句的使用
使用input内置函数来从键盘输入内容
input(*args, **kwargs)
user_name = input('请输入用户名:')
, **kwargs)
user_name = input('请输入用户名:')
无论键盘输入的内容是什么类型,input获取的内容一律是字符串类型(str)。