f是format函数的缩写

发布时间 2023-04-22 23:10:22作者: sangern

python中的f是format函数的缩写,用于格式化输出。
python有两种除法,普通除法 a/b ,不论a,b精度 得到的都是浮点数;a//b , 得到一个舍弃小数位的整数结果,所以结果永远是小于等于普通除法的解
大小写敏感
交互模式下,上次输出的表达式会赋给变量 _

round函数 round(price, 2)
支持 复数:3+5j

π是使用math.pi变量来表示的
import math
math.pi
pai = _
print(pai)
round(pai,3)


'doesn\'t' # use \' to escape the single quote...
'"Yes," they said.'
"\"Yes,\" they said."
'"Isn\'t," they said.'

print('First line.\nSecond line.') # here \n means newline!


>>> mystr1='Hello Kity'
>>> mystr2='PPP'
>>> print(mystr1,mystr2)
Hello Kity PPP
>>> print(mystr1+mystr2)
Hello KityPPP