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
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值