计算机导论第一课笔记二(使用PYTHON)

来源:互联网 发布:视频监控录像软件 编辑:程序博客网 时间:2024/05/22 15:39

字符串相关的问题

1、四舍五入的问题

# x = 3.14159 # >>> 3 (not 3.0)# x = 27.63 # >>> 28 (not 28.0)# x = 3.5 # >>> 4 (not 4.0)x = 3.14159num = x + 0.5b = str(num)a = b.find('.')print b[:a]
显示内容为3。


2、判断回文

#-1表示回文string[::-1]


3、字符串长度

test = "Python"length = len(test)