Last updated: 12 Jun 25 13:47:05 (UTC)

1.字符串(string)

字符串(string)

方法

方法 说明
title 以空格前后各作为一个单位,每个单位首字母大写
upper 全部字母都大写
lower 全部字母都小写
rstrip 默认值: 删除右边所有空格,换行符和制表符 / 带参数: 循环多次挨个删除右侧中与参数相同的字符,直到最右侧的字符不和参数内的字符相同为止
lstrip 默认值: 删除左边所有空格,换行符和制表符 / 同上
strip 默认值: 删除两侧所有空格,换行符和制表符 / 同上
removeprefix 删除前缀,必须带参
removesuffix 删除后缀,必须带参

示例

words = “I wanna go home!”
print(words.title())  # I Wanna Go Home!
words = “I wanna go home!”
print(words.title())  # I Wanna Go Home!

注意

>>> a = "https://shiniei.top"
>>> print(a.lstrip("https://"))
iniei.top
>>> a = "https://shiniei.top"
>>> print(a.lstrip("https://"))
iniei.top

f 字符串

在字符串中使用变量

first_name = "Amy"
last_name = "Mire"
print(f"{first_name} {last_name}")
first_name = "Amy"
last_name = "Mire"
print(f"{first_name} {last_name}")

转义字符

转义字符 说明
\t 制表符相当于Tab键,对齐
\n 换行符