若是下须要写一个很是很是长的字符串,须要跨多行,可使用
三个引号代替普通的引号
#长字串时使用''' '''
print '''This is a very long string
It continues here.'''
字符串跨行 能够在结尾加上“\”
Python中的原始字符串以 r 开头,使用原始字符串能够避免字符串中的转义字符带来的问题
#转义字符,\n表示换行
print 'hello,\nworld'
print 'c:\nowwhere'
print r'c:\nowwhere' #原始字符串的格式,使用r,字符串中\不会进行转义
#注意,使用 r 后,不能在结尾字符串不能是反斜线,若是须要最后一个是反斜线,能够这么处理
print r'c:\Progarm Files\foo\bar''\\' E
#输出结果
hello,
world
c:
owwhere
c:\nowwhere
c:\Progarm Files\foo\bar\
函数 |
描述 |
abs(number) |
返回数字的绝对值 |
cmatch.sqrt(number) |
返回平方根,也可应用与负数 |
float(object) |
将字符串和数字转换为浮点数 |
help() |
提供给交互式帮助 |
input(prompt) |
获取用户输入 |
int(object) |
将字符串和数字转换为整数 |
long(object) |
将字符串和数字转换为长整型 |
math.ceil(number) |
返回数的上入整数,返回值的类型为浮点数 |
math.floor(number) |
返回数的下舍整数,返回值的类型为浮点数 |
math.sqrt(number) |
返回平方根,不适用与负数 |
pow(x,y[,z]) |
返回 x 的 y 次幂(所得结果对 z 取模) |
raw_input(prompt) |
获取用户输入,结果被看作原始字符串 |
repr(object) |
返回值的字符串表示形式 |
round(number[,ndigits]) |
根据给定的精度对数字进行四舍五入 |
str(object) |
将值转换为字符串 |