返回课程

字符串操作

编程代码 · Python

💡 Python 字符串操作:f-string 格式化、分割、连接、大小写转换
greeting = f'Hello, {name}!'// f-string 格式化:用 {} 插入变量值
words = sentence.split(' ')// split() 按空格分割句子为单词列表
joined = '-'.join(words)// join() 用连字符 - 将列表元素连接成字符串
upper = text.upper()// upper() 转为全大写
stripped = text.strip()// strip() 去除首尾空白字符
found = 'python' in text.lower()// in 运算符检查子串是否存在(先转小写再判断)
0 字/分0% 准确
🐵
g左手食指
ESC 暂停 退格