前言
打算开始更一些Python基础文章,因为已经反复学习过基础语法三次,但使用频率不高,忘记的较快,算是给自己记录一份笔记吧
简介
字符串就是一系列字符,在Python
中,字符串是用引号包裹起来的,可以是单引号,也可以是双引号,如:
"String"
'String'
首字母大写显示每个单词
word = "Sometimes ever. sometimes never"
print(word.title())
转大写
word = "Sometimes ever. sometimes never"
print(word.upper())
转小写
word = "Sometimes ever. sometimes never"
print(word.lower())
合并字符串
word_one = "Sometimes ever."
word_two = "sometimes never"
word = word_one + " " + word_two + "!"
print(word)
制表符
print("\tSometimes ever.")
换行符
print("\nSometimes ever. \nsometimes never")
删除末尾空白
word = "Sometimes ever. sometimes never "
print(word.rstrip())
删除开头空白
word = " Sometimes ever. sometimes never"
print(word.lstrip())
删除两端空白
word = " Sometimes ever. sometimes never "
print(word.strip())