38 lines
846 B
Python
38 lines
846 B
Python
# 字符串的方法
|
|
# 1、str.lower() 返回字符串的str的副本(指定字符串不改变) 全部字符小写
|
|
str='ABCdef'
|
|
print(str.lower()) #abcdef 返回新的小写的字符串
|
|
print(str) #ABCdef 原来的字符串不变
|
|
|
|
# 2、str.upper() 返回字符串的str的副本(指定字符串不改变) 全部字符大写
|
|
str='abcDEFGH'
|
|
print(str.upper()) #ABCDEFGH 返回新的大写的字符串
|
|
print(str) #abcDEFGH 原来的字符串不变
|
|
|
|
# 3、str.islower() 当字符串都是小写的时候 返回True 否则返回False
|
|
str1='abcedfgh'
|
|
str2='helloA'
|
|
str3='HELLO'
|
|
print(str1.islower()) #True
|
|
print(str2.islower()) #False
|
|
print(str3.islower()) #False
|
|
|
|
# 4、str.isnumeric() 当字符串都是数字的时候 返回True 否则返回False
|
|
str1='12356'
|
|
str2='qqq123'
|
|
print(str1.isnumeric()) #True
|
|
print(str2.isnumeric()) #False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|