码迷,mamicode.com
首页 > 编程语言 > 详细

Python3中isdigit(), isdecimal(), isnumeric()的区别和字符串的常用方法

时间:2019-04-15 14:44:09      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:替换   nic   可迭代对象   isl   ace   swa   方法   区别   转换   

# 全部小写
string.lower()
# 全部大写
string.upper()
# 是否全部小写
string.islower()
# 是否全部大写
string.isupper()
# 首字母大写
string.capitalize()
# 大小写转换
string.swapcase()
# 检查字符串是否是以 str 开头
string.startswith(str)
# 检查字符串是否是以 str 结束
string.endswith(str)
# 判断是不是纯阿拉伯数字
string.isdigit()
# 判断是不是字母和数字
string.isalnum()
# 判断是不是纯字母和汉字
string.isalpha()
# 返回列表,以 str 为分隔符拆分 string
string.split(str="")
# 返回字符串,以 string 作为分隔符
string.join(可迭代对象)
# 替换字符串
string.replace(old_str, new_str)

"""
isdigit(), isdecimal(), isnumeric()的区别

isdigit()
True: Unicode数字,byte数字(单字节),全角数字(双字节)
False: 汉字数字,罗马数字,小数
Error: 无 

isdecimal() 
True: Unicode数字,全角数字(双字节) 
False: 罗马数字,汉字数字,小数
Error: byte数字(单字节) 

isnumeric() 
True: Unicode数字,全角数字(双字节),罗马数字,汉字数字 
False: 小数 
Error: byte数字(单字节)
"""

Python3中isdigit(), isdecimal(), isnumeric()的区别和字符串的常用方法

标签:替换   nic   可迭代对象   isl   ace   swa   方法   区别   转换   

原文地址:https://www.cnblogs.com/hellomrr/p/10710285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!