【python 基础二】

1、变量

必须由数字、字母、下划线任意组合,且不能数字开头

不能是python关键字:

'and', 'as', 'assert', 'break', 'class', 'continue',
'def', 'del', 'elif', 'else', 'except', 'exec',
'finally', 'for', 'from', 'global', 'if', 'import',
'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',
'raise', 'return', 'try', 'while', 'with', 'yield'

2、常量

python没有特别定义常量,约定俗成就是名字大写。如:BIR_OF_CHINA = 1949

3、用户交互:input

流程:1、等待输入 2、把输入的内容赋值给前面的变量

注意:input 出来的数据全部都是str

4、基础数据类型,如果想知道某个变量是什么类型,可以使用type()

*数字:int 1,2,3

运算:+ - * / %(取余数),

数值转换成字符串:str(int)

*字符串:str 

python 中凡是用引号引起来的都是字符串

运算:+(相当于字符串拼接) *(str*int)

字符串转换成数字:int(str) 注意:str必须是数字组成的

*bool:布尔值 True False

5、if 

if 条件: 

-------------------

if 条件:

else:结果

------------------

if 条件:

elif 条件:

else:结果

6、while

while 条件:

  循环体

终止循环的方法:1、改变条件,使其不成立 2、break

注意break(跳出整个循环体) 和 continue(结束本次循环,再次判断条件)

猜你喜欢

转载自www.cnblogs.com/dantothefourth/p/10359123.html