Python字符串

#当一句中有单引号的时候,字符串用双引号
print ("Let's go" )
#或者使用转义字符处理字符串中的单引号
print ('Let\'s go')
#字符串拼接
x="Hello "
y="World!"
print (x+y)
#str 把值转化为合理的字符串
print (str("10000L"))
#repr 创建一个字符串,以合法的形式表示值
print (repr ("100L"))

temp=18
print ("The temperature is "+repr (temp))

#单引号和双引号基本没有啥区别
name=input('What is your name:')
print  ("My name is  "+name +'!')

#如果一个字符串需要跨多行,使用三个引号代替普通引号或者三个双引号
print ('''This is a very long string. This is a very long string. This is a very long string. This is a very long string.
This is a very long string. This is a very long string. This is a very long string.This is a very long string''')

print ("""This is a very long string. This is a very long string. This is a very long string. This is a very long string.
This is a very long string. This is a very long string. This is a very long string.This is a very long string""")

#下面的使用反斜线进行转义
path1='C:\\n0where'
print (path1)

#原始字符以r开头,原始字符串最后一个字符串不能是反斜线
path2=r'C:\n0where'
print (path2)

#如果希望原始字符只以一个反斜线结尾,简单方法就是转义
path2=r'C:\n0where''\\'
print (path2)

执行结果:

posted @ 2017-08-10 18:11  零度咖啡  阅读(101)  评论(0)    收藏  举报