python下的isdigit函数:

   isdigit() 方法检测字符串是否只由数字组成。

语法

isdigit()方法语法:  str.isdigit()

示例代码如下:

结果:

  

我想说的重点在于:

  这里面会有一个坑,那就是。Number = input("1234:")即从控制台上获取一串值

那么就有

python input() 相等于 eval(raw_input(prompt)) ,用来获取控制台的输入。

raw_input() 将所有输入作为字符串看待,返回字符串类型。而 input() 在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型( int, float )。

当输入全数字字符串时,这时候在使用Number.isdigit()就会报错(AttributeError: 'int' object has no attribute 'isdigit'),已经是int类型的值,在使用该函数,肯定会报错。

那么最好是选用raw_input()函数,作为动态输入方法,负责就会掉入坑。

AttributeError: 'int' object has no attribute 'isdigit'(python下的isdigit函数)的更多相关文章

  1. AttributeError: 'int' object has no attribute 'log'

    我们有时候在对组数进行操作时候,偶尔会出现这个问题. 比如: #coding:utf- import pandas as pd import numpy as np if __name__ == '_ ...

  2. 解决代理池的问题AttributeError: 'int' object has no attribute 'items'

    https://blog.csdn.net/mygodit/article/details/86689127

  3. AttributeError: 'int' object has no attribute 'upper'

    因为安装的openpyxl版本是2.3.4,而代码是: sheet.cell(rownumber, 1).value = data['id']参数不对,应该是: sheet.cell(None, ro ...

  4. [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'

    原因:openpyxl版本低,需升级 pip install --upgrade openpyxl

  5. AttributeError: 'str' object has no attribute 'lowerr' Python常见错误

    方法名拼写错误 检查方法名拼写,如有错误改正即可 特别注意m和n

  6. AttributeError: 'module' object has no attribute 'enableTrace'

    Traceback (most recent call last): File "Long-lived-connection.py", line 29, in <module ...

  7. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  8. python提示AttributeError: 'NoneType' object has no attribute 'append'【转发】

    在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append' a=[] b=[1,2,3,4] a = a.appe ...

  9. Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'

    使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...

随机推荐

  1. Android自定义控件实战——滚动选择器PickerView

    转载请声明出处http://blog.csdn.net/zhongkejingwang/article/details/38513301 手机里设置闹钟需要选择时间,那个选择时间的控件就是滚动选择器, ...

  2. 通过Comparable来实现对自身的比较

    import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.Equa ...

  3. java生成32的md5签名串

    import java.security.MessageDigest; import lombok.extern.slf4j.Slf4j; /** * 签名帮助类 * * @author yangzl ...

  4. 关于安装 Microsoft Office

    安装 Microsoft Office 道路可谓漫漫…… 学校信息网络中心提供的“正版Office”安装了好几次都没成功…… [关于安装包和安装] 看了这篇经验,还不错:  office2018官方下 ...

  5. --defaults-file 不能用?

    今天在测试mysql多实例时发现mysqld_safe --user --defaults-file 怎么都无法启动,后来发现是必须按顺序,先写--defaults-file才可以. mysqld_s ...

  6. Linksys WRT610n V2 刷ddwrt后安装entware-ng,使用opkg

    安装步骤很简单,首先启用usb.jffs.等. 然后: mkdir -p /jffs/opt mount -o bind /jffs/opt /opt wget -O - http://pkg.ent ...

  7. coon's patch

    作者:桂. 时间:2018-05-23  06:11:54 链接:https://www.cnblogs.com/xingshansi/p/9070761.html 前言 早晨突然想到计算机模型的各种 ...

  8. Android 源码学习

    工具篇:如何使用 Visual Studio Code 阅读 Android 源码:https://jekton.github.io/2018/05/11/how-to-read-android-so ...

  9. Linux应该知道的技巧

    https://coolshell.cn/articles/8883.html https://www.quora.com/Linux/What-are-some-time-saving-tips-t ...

  10. 简化实现动态行列转置的SQL

    动态行列转换的计算在实际业务中非经常见,网上各类技术论坛上都有讨论,比方以下这些问题: http://www.iteye.com/problems/87788 http://bbs.csdn.net/ ...