Home  >  Article  >  Backend Development  >  Recommended common string methods in python

Recommended common string methods in python

小云云
小云云Original
2018-03-30 17:12:261170browse

This article mainly shares with you the recommendations of common string methods in python, mainly in text, hoping to help everyone.

String.isalnum() All characters are numbers or letters. If true, it returns Ture, otherwise it returns False.

String.isalpha() All characters are letters. If true, it returns Ture, otherwise it returns False.

String.isdigit() All characters are numbers. If true, it returns Ture, otherwise it returns False.

String.islower() All characters are lowercase. If true, it returns Ture, otherwise it returns False.

String.isupper() All characters are uppercase. If true, it returns Ture, otherwise it returns False.

String.istitle() All words are capitalized. If true, return True, otherwise return False.

String.isspace() All characters are whitespace characters. If true, it returns Ture, otherwise it returns False.

print('asdA'.isalpha())  # 纯字母
print('123'.isdecimal())  # 纯数字
print('1.1'.isdigit())  # 是否为整数
print('ZX'.isupper())  # 是否为大写
a = '   字  符 \n  创 '
c= a.strip()#默认去掉字符串两边的空格和换行符\n
c=a.lstrip()#默认去掉左边的空格
c=a.rstrip()#默认去掉右边的空格
print('c....',c)
print('a....',a)
words = 'https: day is wonderfullday'
print(words.strip('day'))#如果strip方法指定一个值的话,那么会去掉这个指定的值
print(words.count('a'))#统计字符串出现次数
# print(words.index('z'))#找下标,如果找不到会报错
print(words.find('z'))#找下标,如果找不到元素的话,会返回-1
print(words.replace('day','DAY')) #替换字符串
print(words.isdigit()) # 判断字符串是否为纯数字
print(words.startswith('https:'))#判断字符串是否以xx开头
words.endswith('DAY')#判断是否以某个字符串结尾
print(words.upper()) #变成大写
print(words.lower()) #变成小写
username ='adbdsaf33333'
print(username.isalpha())#判断字符串是否全为字母
print(username.isalnum())#判断是否包含字母和数字,它是由字母或数字就返回True

Related recommendations:

PHP common string processing function usage examples [conversion, escaping, interception, comparison, search, reverse, cut]

The above is the detailed content of Recommended common string methods in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn