python与用户的交互
input()函数只是作为一个过渡阶段后面基本不会用到
无论输入什么input接收的都是字符串
格式化输出
形如:
print("我的名字叫%d,我的年龄是%d,我的身高为%d."%(name,age,height))
的输出就叫格式化输出 其中%d就叫占位符
format格式化
形如:
print("My name is {},My age is {},My height is {}".format(name,age,height))
或者:
print("My name is {name},My age is {age},My height is {height}".format(name = name,age = age,height = height))
f-string格式化
形如:
print(f"My name is {name},My age si {age}:2f,My height is {height}.")
其中:2f 指保留2位小数
算术运算符
+ - * / % //
比较运算符
> ,< ,>=,<=,==,!=
赋值运算符
=
逻辑运算符
and,or,not
身份运算符
is 比较的是id
python运算符优先级
链式赋值
x = y = z = 10
交叉赋值
x,y = y,x
解压缩
nick_hobby_list = ['read','run','music','code']
,hobby1,hobby2, = nick_hobby_list
print(hobby1)
print(hobby2)
print(hobby1 = nick_hobby_list[1])
print(hobby2 = nick_hobby_list[2])