unicode转换成string★python字符串内置功能(3)

电脑杂谈  发布时间:2018-02-14 08:34:10  来源:网络整理

str.isalpha() -->Bool (True or False)判断字符串String是否只由字母组成,并且至少有一个字符(不为空)

'dobi'.isalpha()
# True
'do bi'.isalpha()
# False
'dobi123'.isalpha()
# False
'张'.isalpha()
# True

str.isdecimal()小数; str.isdigit()数字; str.isnumeric()数值 -->Bool (True or False)判断字符串String是否只由小数/数字/数值组成,并且至少有一个字符(不为空)

string转bigdecimal_Date转换成string_unicode转换成string

三个方法的区别在于对 Unicode 通用标识的真值判断范围不同:

isdecimal: Nd, (小数) all decimals are digits, but not all digits are decimals(所有小数都是数字,但不是全部数字都是小数)

isdigit: No, Nd, (数字)

isnumeric: No, Nd, Nl (数值)

digit与decimal的区别在于有些数值字符串,是digit却非decimal,具体戳这里

num = '\u2155'
print(num)
# ⅕
num.isdecimal(), num.isdigit(), num.isnumeric()
# (False, False, True)
num = '\u00B2'
print(num)
# ²
num.isdecimal(), num.isdigit(), num.isnumeric()
# (False, True, True)
num = "1"  #unicode
num.isdecimal(), num.isdigit(), num.isnumeric()
# (Ture, True, True)
num = "'Ⅶ'" 
num.isdecimal(), num.isdigit(), num.isnumeric()
# (False, False, True)
num = "十"
num.isdecimal(), num.isdigit(), num.isnumeric()
# (False, False, True)
num = b"1" # byte
num.isdigit()   # True
num.isdecimal() # AttributeError 'bytes' object has no attribute 'isdecimal'
num.isnumeric() # AttributeError 'bytes' object has no attribute 'isnumeric'

'def'.isidentifier()
# True
'with'.isidentifier()
# True
'false'.isidentifier()
# True
'dobi_123'.isidentifier()
# True
'dobi 123'.isidentifier()
# False
'123'.isidentifier()
# False

str.islower()-->Bool (True or False)判断字符串中是否是有效标识符

str = "programmer"
sub = "PYTHON"
print(str.islower())
# True
print(sub.islower())
# False
'ß'.islower()   #德语大写字母
# False


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-77070-3.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...