Published: 01 Dec 2025 › Updated: 01 Dec 2025
python字符串的一些笔记 part1
修改首字母大小写
使用.title()
示例
name = 'ada lovelace'
print(name.title())
注意.title()后面的()留空即可,并且需要是英文半角
让全字段都大写或者小写
大写
使用.upper()
小写
使用.lowe()
规则同上
在字符串中使用变量
先看这一段代码
first_name = 'ada'
last_name = 'lovelace'
full_name = f'{first_name}{last_name}'
print(full_name)
看看输出的结果
可知f'{}'即使调用前面的变量
其实是f'任意字符串{}'要调用的字段名必须用{}包裹起来
可以看看这一段
first_name = 'ada'
last_name = 'lovelace'
full_name = f'first_name,last_name{first_name}{last_name}'
print(full_name)
使用制表符或换行符来添加空白
制表符
\t
换行符
\n
删除空白
末尾
.rstrip
开头
.lstrip
前后
.strip
Leave python字符串的一些笔记 part1 to:
Read more #hive-188262 posts
Best Posts From 谷雨の梦
We have not curated any of zmx's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.