We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
# 通过索引获取字符串中的某个字符串 s1 = 'hello world' print(s1[0]) print(s1[2]) # 分片 print(s1[6:9]) ## 索引6、7、8 print(s1[6:]) # 索引6以及以后所有 print(s1[::2]) # 步长,2 每两个取一个(隔一个取一个) print(s1[::-1]) # 倒序 # 乘法 s2 = "xyz" print(10 * s2) # 重复输出10次 print(s2 * 20) # 同上 # 判断字符在字符串中是否存在 print('b' in s2) print('y' in s2) # 判断字符不在字符串中 print('b' not in s2) print(len(s1)) ## 取长度 print(min(s2)) ## 取字符串中最小ASCII print(max(s2)) ## 取字符串中最大ASCII ## 列表 a = [1,2,3,0,6] print(2 not in a) ## 判断不在 print(max(a)) #取最大值 print(min(a)) #取最小值 print(len(a)) # 取列表长度 print(10 * a) # 列表元素首尾相接重复10次 a[0] = 20 # 列表中可以设置某个角标对应值,字符串不行
Python字符串支持分片、乘法、in和not in运算符,以及列表支持的一些函数, 如len、min和max函数
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Python字符串支持分片、乘法、in和not in运算符,以及列表支持的一些函数,
如len、min和max函数
The text was updated successfully, but these errors were encountered: