pass语句
举例说明
if n>2:
pass 如果if n>2下面什么东西也不写,运行程序会报错,写上pass则不会报错,pass表示什么也不做,只是占个地方,表示我是明白python的语法规则的,其中三个点(...)和pass的用法相同
格式化输出 %s
'其他内容%s其他内容%s'%(变量名1,变量名2)
name = input('name:')
traffic = input('traffic:')
print('昨天%s开着%s去玩了'%(name,traffic))
print('红球%s,蓝球%s'%('30','20'))
print('红球%s,蓝球%s'%(30,20))
print('红球%d,蓝球%d'%(30,20))
print('红球%d,蓝球%d'%('30','20')) TypeError: %d format: a number is required, not str d是digital的简写,后面只能接数字,不能接字符串
运算符
算术运算符 + - * / // %
比较运算符 == >= <= > < !=
赋值运算符 = += -= *= /= %=
逻辑运算符
and 且 都为真,结果才是真,一个为假就是假
or 或, 一个为真,则为真
not 非 not True == False
not False == True
优先级 括号的优先级>not>and>or
面试会考的题目
print(1 or 5) =>1 a or b 如果a为真,则结果为a, 否则结果为b. and 与or相反。
print(0 or 5) => 5
print(not 3>1 or 9>7 and 8 or 9) # not 3>1 or 9>7 and 8 or 9 => F or T and 8 or 9 => F or 8 or 9 =>8 or 9 => 8
身份运算符
is
is not
a =1
b=1
print(a is b) ->打印出来的结果是True