python的一些小知识点

1.用format格式化字符串比%s,%d应该要好用   具体可以看https://www.runoob.com/python/att-string-format.html

举个栗子:

  print("{}执行用了{}ms".format(func.__name__,time.time() - start_time))  

2.x and y :如果 x为真,则值为y,否则为x

   x or y    :如果 x为真,则值为x,否则为y

举个栗子,ab都为真:

  1  and  a  or  b: a

  0  and  a  or  b: b

 

猜你喜欢

转载自www.cnblogs.com/hooo-1102/p/12143628.html