'''
1、表示 四种方式
'''
str1="hello"
str2='world'
str3='''Python'''
str4="""Python is a
new programming language
"""
print(str1,str2,str3,str4)
'''
2、连接,字符串连接
'''
print(str1+" "+str2)
'''
3、裁切
指定开始索引和结束索引,以冒号分隔,以返回字符串的一部分。
获取从位置 2 到位置 5(不包括)的字符:
'''
b = "Hello, World!"
print(b[2:5])
'''
4、负的索引
使用负索引从字符串末尾开始切片:
获取从位置 5 到位置 1 的字符,从字符串末尾开始计数:
'''
b = "Hello, World!"
print(b[-5:-2])
'''
5、字符串长度
如需获取字符串的长度,请使用 len() 函数。
len() 函数返回字符串的长度:
'''
a = "Hello, World!"
print(len(a))
'''
6、其他内置方法。
'''
a = " Hello, World! "
print(a.strip())
print('hello python'.capitalize())
print('Hello PythOn'.casefold())
print('Hello PythOn'.swapcase())
print('Hello Python'.upper())
print('hello python'.title())
print('hello python'.center(20,'0'))
print('hello python'.zfill(20))
print('hello python'.count('h'))
print('hello python'.encode())
print('hello python'.endswith('n'))
print('hello python'.endswith('N'))
print('hello python'.expandtabs(3))
print('hello python'.find('o'))
print('hello python {}'.format('world'))
print('hello python {0},{1}'.format('world',' say hi'))
print('hello python world '.format_map('world'))
print('hello python '.index('o'))
print('123 '.isalnum())
print('ascv '.isalpha())
print('12312 '.isdecimal())
print('12312 '.isdigit())
print('12312 '.isnumeric())
print('12312 '.isidentifier())
print('12312 '.islower())
print('12312'.isprintable())
print('12312'.isspace())
print('12312'.istitle())
print('12312'.isupper())
print('12312'.join('15'))
print('hello python '.ljust(20,'='))
print('hello python '.rjust(20,'='))
print('hello python '.lower())
print('hello python '.lstrip())
print('hello python '.partition(' '))
print('hello python '.replace('on','on world'))
print('hello python '.rfind('on'))
print('hello python '.rindex('on'))
print('hello python '.rpartition('e'),'============================')
print('hello python '.rsplit())
print('hello python '.rstrip())
print('hello python '.split())
print('hello python '.splitlines())
print('hello python '.startswith('h'))
print('hello python '.strip('h'))