用引号括起来的就是字符串,单引号或者双引号均可
string1 = “Python”
或 string1 = 'Python'
字符串常用操作:
1、获取字符串长度:len
2、拼接字符串:+
3、大小写转换:lower,upper
4、转义符:\
5、去除两端空格及换行符: strip()
字符串常用操作演示。
str1 = "Python"
len(str1)
str2 = "Excel"
print(str1+str2)
print(str1.lower())
print(str1.upper())
# \n,换行符
print('Python\nExcel')
print(r'Python\nExcel')
str1 = ' Python\n'
print(str1)
print(str1.strip())