Python中不需要对变量指定数据类型
input() 屏幕上打印可选提示字符串,返回用户输入的字符串
print()屏幕上打印字符串,默认后边会追加一个换行符,可用end把换行符替换为其它的
for iin range(1,10):
# print(i)
print(i,end =" ")
python中的关键字
False def if raise
None del import return
True elif in try
and else is while
as except lambda with
assert finally nonlocal yield
break for not
class from or
continue global pass
单行定义多个变量、赋值
>>> a , b = 45, 54
>>> a
45
>>> b
54
用这个方法交换两个变量的值很方便
>>> a, b = b , a
>>> a
54
>>> b
45
关系运算符
逻辑运算符
关键字:and、or、not
关系运算符与逻辑运算符的组合,取非得话,可以加not,逻辑运算符的优先级又低于关系运算符,在它们之中,not 具有最高的优先级,or 优先级最低,所以 A and not B or C 等于 (A and (notB)) or C。当然,括号也可以用于比较表达式。
数据类型转换: