一.三目(元)运算符 定义:就是 if...else...语法糖前提:简化if...else...结构,且两个分支有且只有一条语句注:三元运算符的结果不一定要与条件直接性关系 cmd = input('cmd: ') print('可以转化为数字') if cmd.isdigit() else print('不可以转化为数字') a = 20 b = 30 res = a if a > b else b # 求大值 print(res) res = 'b为小值' if a >…
其他语言:php 判定条件?为真时的结果:为假时的结果 $a=88 $b=99 $res = $a>$b?$a>$b 搞笑的Python:令人意想不到的语法形式 true_value if condition else false_value它的意义是:如果condition为真,计算并返回true_value,并跳过false_value的计算,否则计算并返回false_value.它完全等价于完整形式. a=99 b=88 res = a if a>b else b print(re…
Set 集合 set - unordered collections of unique elements 创建一个set/一个空set # create a new set set1 = {1,2,3} print(type(set1)) # result => <class 'set> set2 = set() print(type(set2)) # create an empty set, result => <class 'set'> # as the obje…