字符串相关的问题
1、四舍五入的问题
# x = 3.14159
# >>> 3 (not 3.0)
# x = 27.63
# >>> 28 (not 28.0)
# x = 3.5
# >>> 4 (not 4.0)
x = 3.14159
num = x + 0.5
b = str(num)
a = b.find('.')
print b[:a]
显示内容为3。
2、判断回文
#-1表示回文
string[::-1]
test = "Python"
length = len(test)