目录
本章将会讲解Python编程中字符串的组成方式,重点掌握。
①字符串相加
②字符串格式化
%s %d %f
str.format()
python3.6.4以上 引入 f''
print("1"+"2") #得12 字符串用+做拼接
弊端:%类型需要考虑数据类型
name = "doudou"
age = 20
#挖坑/填坑
# %s----> str 名字
# %d----> decimal 年龄
# %f----> float 浮点数
print("%s年龄为**%d"%(name,age))
name = "doudou"
age = 20
# str.format() S.format(*args, **kwargs) -> str 字符串的一个方法返回字符串
#{}——————> 占坑 好处1:不用考虑数据类型 好处2:可以切换位置
print("{1}年龄为{0}".format(age,name))
name = "doudou" #python 3.6.4以上版本
age = 20
# f''
# {} --> 占坑
print(f"{name}年龄为{age}")
创作不易,求关注,点赞,收藏,谢谢~