1、字符串函数
test_str=' CHINA '
去除字符串前后制表符空格:test_str.strip() >> 'CHINA'
去除字符串左边制表符空格:test_str.lstrip() >> 'CHINA '
去除字符串右边制表符空格:test_str.rstrip() >> ' CHINA'
test_str='china'
字符串所有变大写:test_str.upper() >> 'CHINA'
test_str='CHINA'
字符串所有变小写:test_str.lower() >> 'china'
test_str='china'
字符串首字母变大写:test_str.capitalize >> 'China'
test_str='i love china'
字符串所有单词首字母大写:test_str.title() >> 'I Love China'
test_str='CHINA'
字符串判断是否全部大写:test_str.isupper() >> True
字符串判断是否全部小写:test_str.islower() >> False
test_str=1234a
字符串判断是否全部数字:test_str.isdigit() >> False
test_str='CHINA'
字符串判断开头字符串是否相等:test_str.startswith('CHI') >> True
test_str='CHINA'
字符串判断结尾字符串是否相等:test_str.endswith('NB') >> False
password='123'
input_password='123456789'
查找字符串在另一字符串所在位置:
input_password.find(input_password) >> 3 (如果没找到返回-1)
input_password.index(input_password) >> 3 (如果没找到直接报错)
计算字符串在另一字符串里的个数:
input_password.count('3') >> 1
替换字符串:
‘abce’.replace('a','b') >> 'bbce'
'apple orange'.replace('apple','banana') >> 'banana orange'
计算字符串长度:
len(password) >> 3
2、元组(元组是不可变序列)
t = tuple('python') >> t -> ('p','y','t','h','o','n')
t = ('p','y','t','h','o','n') >> t -> ('p','y','t','h','o','n')
t = ('My','age','is',19) >> t -> ('My','age','is',19)
t = 'My','age','is',19 >> t -> ('My','age','is',19) t[0] -> 'My' t[0,2] -> ('My','age')
t = ('Solo',) >> t -> (Solo,)
t = 'Solo', >> t -> (Solo,) //元组括号可加可不加,但是元组中只有一个元素时后面必须要加逗号
t = ('My','age','is','19') >> ' '.join(t) -> My age is 19 '+'.join(t) -> My+age+is+19



