Python-string的简单使用
字符串定义
- str = “ xxx”
- str = ' xxx '
- str = """ xxxx """
字符串拼接
只能字符串与字符串评接
- 利用 + 来实现,如“qq” + “xxxx” -> “qqxxxx”
格式化实现拼接
利用%s作为占位符,再在后面接%来对占位进行填充
- 字符串与字符串拼接
b = "%s is" % a
print(b)
age = 23
- 字符串与其他类型进行拼接
c = b + " %s" % age + " 岁"
- 快速格式化 f"内容{变量}"
introduce = f"my name is {name},my birth is {birth},my age is {age}"

浙公网安备 33010602011771号