字符串的定义,用双引号与单引号都可以
name="hello'world!" 正确
name="hello"world!" 错误
name = 'hello"world' 正确
name = 'hello'world' 错误
title方法:将字符串中单词的首字母变为大写,其他字母均为小写
name="love live"
print(name.title())
输出为:Love Live。无论name是"lOVE lIVE"还是"LOVE LIVE",其输出结果都一样。
upper()方法:将字母全部变为大写字母。
lower()方法:将字母全部变为小写字母。
rstrip()方法:去除字符串中末尾的空格符
lstrip()方法:删除字符串开头的空格
strip()方法:删除开头与末尾的空格
字符串与数字的合并:
age=23
message="Happy"+age+"rd Day" //错误
message="Happy"+str(age)+"rd Day" //正确
message="happy ".title()+str(age)+" rd day".title()
输出Happy 23 Rd Day