1.字符串 用引号括起来的就是字符串,包括单双引号 name = "what is your name?" print(name.title()) //title函数输出字符串首字母大写 print(name.upper()) //全部大写 print(name.lower()) //全部小写

2.合并(链接)字符串

first_name = "bigbeat" last_name ="wu" full_name = first_name + "." +last_name //合并在一个变量 print(full_name) print("Hello " + full_name.title() + '!') message = "Hello " + full_name.title() + '!' //也称拼接在一个变量 print(message)

3.用制表符或换行符来添加空白

print("\tbigbeat.wu") // \t制表符:空格;\n换行符 print("my name :\n\tbigbeat.wu")

4.删除空格函数rstrip():字符串最末尾的空格;lstrip():字符串最开始的空格

irst_name = " bigbeat" last_name = "wu " full_name = first_name + '.' + last_name + '!' print(full_name) print(full_name.rstrip()) //并不是把其中某个字符串的末尾空格删掉,而是整个字符串的最末尾空格删掉 print(full_name.lstrip()) //把整个字符串的最开始的空格删掉 first_name = first_name.lstrip() print(first_name)

5.字符串尽量用双引号 6.str()函数:将非字符串值表示字符串

age = 23 message = "Happy " + str(age) + "rd Birthday!" //将int 转化为字符串 print(message)