运算符 描述 实例 yield x 生成器函数发送协议 lambda args: expression 生成匿名函数 x if y else z 三元选择表达式(c系列有的 python也要有) >>> True if 1>0 else False True 下面的内容摘自菜鸟教程:http://www.runoob.com/python/python-operators.html 人家做的还是不错的,不过上面这个没有写 Python算术运算符 以下假设变量a为10,变
Python 支持格式化字符串的输出 .尽管这样可能会用到非常复杂的表达式,但最基本的用法是将一个值插入到一个有字符串格式符 %s 的字符串中. 在 Python 中,字符串格式化使用与 C 中 sprintf 函数一样的语法. 如下实例: #!/usr/bin/python print "My name is %s and weight is %d kg!" % ('Zara', 21) 以上实例输出结果: My name is Zara and weight is 21 kg! p
1.字符串连接 >>> a = 'My name is ' + 'Suen' >>> a 'My name is Suen' >>> a = 'My name is %s'%'Suen' >>> a 'My name is Suen' >>> a = 'My name is %s, Age:%d'%('Suen', 18) >>> a 'My name is Suen, Age:18'>>