python换行方法及 cell() floor() exp() round()函数使用方法

1. python换行

1.1Python 通常是一行写完一条语句,但如果语句很长,我们可以使用反斜杠()来实现多行语句

a = 4
b = 5 
c = 6
d = a + \
    b + \
    c
print(d)
15

1.2 在 [], {}, 或 () 中的多行语句,不需要使用反斜杠(),例如:

lst = ["中国","北京",
      "杭州"]
lst[0]
'中国'

1.3 反斜杠可以用来转义,使用r可以让反斜杠不发生转义。 如 r"this is a line with \n" 则\n会显示,并不是换行。

print(r"this is a line with \n")
this is a line with \n
print("this is a line with \n")
this is a line with 

2. 一些数学函数

#ceil()向上取整,floor()向下取整
import math
a = math.ceil(1.4)
b = math.floor(1.4)
print(a)
print(b)
2
1
c = math.exp(2)
print(c)
7.38905609893065  
#round函数,表示四舍五入,后边的一位数表示要保留的小数位数
d = round(4.2354,2)
print(d)
4.24
#random()生成(0,1)之间的随机数
import random
e = random.random()
e
0.11232659021103464

你可能感兴趣的:(python编程语言)