python中pass返回的值_python中pass语句,格式化输出及运算符介绍

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值