Simple Python Built-in Functions

 

>>>ord('a') - ord('A')
32
>>>chr(98)  
'b'  
#chr(code ) function return the character represent by the code  
>>> str(98)  
'98'  
#notice the difference between str() and chr()  

chr()
ord()
str()
abs(x)    #return the absolute value for x
max(x1,x2,...) #return the largest among x1,x2,. . .  
min(x1,x2,...) #return thesmallest among x1,x2,. . .  
pow(a,b) #return a**b</p>  
round(x,n) #return the float value rounded to n digits after the decimal point  
round(x) #Return an integer nearest to x. If x is equally close to two integers,the even one is returned  

>>>abs(-2)   # is 2
>>>max(1,5,2)# is 5  
>>>min(1, 5, 2) # is 1  
>>>pow(2, 3) #is 8  
>>>round(5.5) #is 6  
>>>round(5.4) # is 5  
>>>round(4.5) #is 4  
>>>round(5.446,2) #is 5.45  
>>>round(5.443,2) # is 5.44


全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 13:47
机械打工仔:你自己匿名可以,这么好的公司就别给它匿名了
点赞 评论 收藏
分享
程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务