python(5)字符串相关知识点
发布时间
阅读量:
阅读量
字符串数据
所谓字符串数据是指两个单引号或双引号之间的任意字符序列,并以str作为其数据类型标识符
#!/usr/bin/python3
x="hello world"
print(x)
print(type(x))
y='你好'
print(y)
print(type(y))

字符串的连接
python中使用“+”连接字符串
str1="36"
str2="D"
str3=str1+str2
print(str3)

多行字符串
str1='''zineinxienihediniedx
xeedxeexjrfijnitamma'''
print(str1)

强制转换为字符串
str1=26
str2=36
str3=str(str1)+str(str2)
print(str3)

强制将字符串转换为整数
str1="36"
str2="66"
str3=int(str1)+int(str2)
print(str3)

st="ee" #错误使用案例
print(int(st))

字符串与整数相乘
str1="36"
str2=str1*4
print(str2)

字符串前+r
取消逸出字符的功能
str1="hello\n world"
print(str1)
str2=r"hello\nworld"
print(str2)

参考资料
Python王者归来 洪锦魁著
本博客是纯粹个人学习,与朋友交流共赏,不存在任何商业目的。
本博客采用了若干网络资源, 原有版权信息尽力标注来源, 但因许多资料被多次引用后难以追溯其原始出处;个别因操作失误可能导致原有数据遗失, 因此希望原作者能够谅解。
如果您对此文章及作品版权归属有疑问,请立即告知我们的版权归属问题。我们将尽快采取措施并致以诚恳的歉意!
全部评论 (0)
还没有任何评论哟~
