Advertisement

python(5)字符串相关知识点

阅读量:

字符串数据

所谓字符串数据是指两个单引号或双引号之间的任意字符序列,并以str作为其数据类型标识符

#!/usr/bin/python3

x="hello world"

print(x)

print(type(x))

y='你好'

print(y)

print(type(y))


67042cf69067444cb9c53dd2a0d72010.jpg

字符串的连接

python中使用“+”连接字符串

str1="36"

str2="D"

str3=str1+str2

print(str3)


c535051e46c54e3282d5b92536122f07.jpg

多行字符串

str1='''zineinxienihediniedx

xeedxeexjrfijnitamma'''

print(str1)


b1b98a7f52e5445bb0c6e73489652fab.jpg

强制转换为字符串

str1=26

str2=36

str3=str(str1)+str(str2)

print(str3)


85e342cabf584f44a2ba43e8418035c5.jpg

强制将字符串转换为整数

str1="36"

str2="66"

str3=int(str1)+int(str2)

print(str3)


24e7c59de1004e6a97cd44de0a537be4.jpg

st="ee" #错误使用案例

print(int(st))


1062253d0cd0409eabe3ada6000c9701.jpg

字符串与整数相乘

str1="36"

str2=str1*4

print(str2)


d90e53dba8c541b48ee57d5278b97a57.jpg

字符串前+r

取消逸出字符的功能

str1="hello\n world"

print(str1)

str2=r"hello\nworld"

print(str2)


e0f1aee73e1746679671086b1bc15f6f.jpg

参考资料

Python王者归来 洪锦魁著

本博客是纯粹个人学习,与朋友交流共赏,不存在任何商业目的。

本博客采用了若干网络资源, 原有版权信息尽力标注来源, 但因许多资料被多次引用后难以追溯其原始出处;个别因操作失误可能导致原有数据遗失, 因此希望原作者能够谅解。

如果您对此文章及作品版权归属有疑问,请立即告知我们的版权归属问题。我们将尽快采取措施并致以诚恳的歉意!

全部评论 (0)

还没有任何评论哟~