双引号或单引号
单引号里放双引号
字符串可以索引位置字符 str[6]
str1="hello python"
str2='我是朱"光伟"'
print(str2)
print(str1[6])
for char in str2:
print(char)
-----------------
D:\Anaconda\python.exe D:/Pycharm/PycharmProjects/python字符串/k01_字符串定义和遍历.py
我是朱"光伟"
p
我
是
朱
"
光
伟
"
Process finished with exit code 0
统计字符串
len(字符串)
字符串.count(字符串)小字符串在大字符串中出现的次数
count不存在是返回值为0
index查询字符串出现的位置
index不存在是会报错
方法 | 说明 |
string.isspace() | 如果string中只包含空格返回ture |
string.isalnum() | 至少有一个字符并且所有字符都是字母或数字则返回ture |
string.isalpha() | 至少有一个字符且所有字符都有字母则返回ture |
string.isdecimal() | 只包含数字返回ture 全角数字 |
string.isdigit() | 只包含数字返回ture 全角数字、(1)、\u00b2 |
string.isnumeric() | 只包含数字返回ture 全角数字、汉字数字 |
string.istitle() | 是标题化的(每个单词首字母大写)返回ture |
string.islower() | 包含至少一个区分大小写的字符,且所有这些(区分大小写的)字符都是小写,返回ture |
string.isupper() | 包含至少一个区分大小写的字符,且所有这些(区分大小写的)字符都是大写,返回ture |
#判断空白字符
space_str=" \t\n\r"
print(space_str.isspace())
#判断字符串