字符串数据

所谓的字符串数据是指两个单引号()之间或是两个双引号()之间任意个数字元符号的数据,它的数据类型代号是 str 。

#!/usr/bin/python3

x="hello world"

print(x)

print(type(x))

y='你好'

print(y)

print(type(y))

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

字符串的连接

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

str1="36"

str2="D"

str3=str1+str2

print(str3)

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

多行字符串

str1='''zineinxienihediniedx

xeedxeexjrfijnitamma'''

print(str1)

 python(5)字符串相关知识点_学习方法_03

强制转换为字符串

str1=26

str2=36

str3=str(str1)+str(str2)

print(str3)

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

强制将字符串转换为整数

str1="36"

str2="66"

str3=int(str1)+int(str2)

print(str3)

 python(5)字符串相关知识点_学习方法_05

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

print(int(st))


 python(5)字符串相关知识点_数据_06

 


字符串与整数相乘

str1="36"

str2=str1*4

print(str2)

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

字符串前+r

取消逸出字符的功能

str1="hello\n world"

print(str1)

str2=r"hello\nworld"

print(str2)

 python(5)字符串相关知识点_数据_08

参考资料

Python王者归来   洪锦魁著

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

本博客利用了部分网络资源,版权归原作者及网站所有,虽力求保存原有的版权信息并尽可能注明来源,但由于很多资料经过多次转摘,已经无法确定真实来源;部分因为操作上的原因 可能已将原有信息丢失,所以敬请原作者原谅。

如果您对此文章及作品版权的归属存有异议,请立即通知我们,我们将在第一时间予以删除,同时向你表示歉意!