#money.isdigit()判断money是不是整数#
今日问答
YOUTUBE频道
欢迎订阅我的bilibili频道
money.isdigit()判断money是不是整数
大家好,我是麦克阿洛。如果你喜欢我的文章,欢迎订阅和关注哦。
isdigit()方法语法:str.isdigit()
3.返回值
如果字符串只包含数字则返回 True 否则返回 False。
4.编写代码
# !/usr/bin/python
# -*- coding: UTF-8 -*-
# 字符串只包含数字
strTest = "123456789"
print(strTest.isdigit()) # 打印结果: True
strTest = "都是字符串的测试代码"
print(strTest.isdigit()) # 打印结果: False
strTest = None
# print(strTest.isdigit()) # 打印结果: AttributeError: 'NoneType' object has no attribute 'isdigit'
strTest = "0"
print(strTest.isdigit()) # 打印结果: True
strTest = "-1"
print(strTest.isdigit()) # 打印结果:False
5. 输出结果:
无
今天的教程到这里就结束了。如果想获得更多的内容,请关注我哦,谢谢大家。
留言与评论(共有 0 条评论) “” |