AttributeError: 'int' object has no attribute 'isdigit'(python下的isdigit函数)
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函数)的更多相关文章
- AttributeError: 'int' object has no attribute 'log'
我们有时候在对组数进行操作时候,偶尔会出现这个问题. 比如: #coding:utf- import pandas as pd import numpy as np if __name__ == '_ ...
- 解决代理池的问题AttributeError: 'int' object has no attribute 'items'
https://blog.csdn.net/mygodit/article/details/86689127
- AttributeError: 'int' object has no attribute 'upper'
因为安装的openpyxl版本是2.3.4,而代码是: sheet.cell(rownumber, 1).value = data['id']参数不对,应该是: sheet.cell(None, ro ...
- [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'
原因:openpyxl版本低,需升级 pip install --upgrade openpyxl
- AttributeError: 'str' object has no attribute 'lowerr' Python常见错误
方法名拼写错误 检查方法名拼写,如有错误改正即可 特别注意m和n
- AttributeError: 'module' object has no attribute 'enableTrace'
Traceback (most recent call last): File "Long-lived-connection.py", line 29, in <module ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- 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 ...
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...
随机推荐
- 人人网框架导入uidGenerator的ID生成方式
人人网框架导入uidGenerator的ID生成方式 2019-03-11 LIUREN SpringBoot2.0 uidGenerator SpringBoot2.0 uidGener ...
- 生成命令行接口--google开源的fire使用体验【python-fire】
在python中,命令行接口常用的argparse 和click,但是相对于python-fire 来说灵活度太缺了,fire可以直接将python中的函数,以命令行显示. 简单的介绍几个例子: #! ...
- sqlite基础
常用命令 sqlite3提供的特殊命令, 以.开头: .help: 帮助 .databases: 列出数据库 .tables: 列出表名 .open dbname: 打开数据库 .save dbnam ...
- SELECT INTO和INSERT INTO SELECT的区别 类似aaa?a=1&b=2&c=3&d=4,如何将问号以后的数据变为键值对 C# 获取一定区间的随即数 0、1两个值除随机数以外的取值方法(0、1两个值被取值的概率相等) C# MD5 加密,解密 C#中DataTable删除多条数据
SELECT INTO和INSERT INTO SELECT的区别 数据库中的数据复制备份 SELECT INTO: 形式: SELECT value1,value2,value3 INTO Ta ...
- 云服务jdk 升级为 OpenJDK11
由于oracle是个碧池,大家都懂,今年来,jdk版本更新的越来越频繁,所以目前商业版本需要收费了 每个企业都要考虑这样的问题,所以嘛,新项目试水肯定是要的,用openJDK11吧, https:// ...
- easyui的datagrid和treegrid的使用
$('#listTree').treegrid({ idField: 'id', treeField: 'menuName', columns: [[ { title: 'Task Name', fi ...
- 猿题库从 Objective-C 到 Swift 的迁移
猿题库从 Objective-C 到 Swift 的迁移 引言 相信没有人会怀疑,Swift 是 iOS 开发未来的主流语言,但是由于 Swift 语言的不断变化以及庞大的迁移成本,真正把项目迁移到 ...
- linux shell命令之wc/split及特殊字符
[时间:2018-07] [状态:Open] [关键词:linux, wc, split, 通配符,转义符,linux命令] 0 引言 整理这篇文章的目的不是为了什么学习,仅仅是为了强化下记忆,以便下 ...
- go module下golang.org如何处理被墙
一.系统提示 go: golang.org/x/sys@v0.0.0-20180905080454-ebe1bf3edb33: unrecognized import path "golan ...
- C# SMTP 邮件发送之QQ邮箱篇
邮件发送大家都已经非常熟悉了,微软自带的System.Net.Mail也很好用,那为什么还要说呢? QQ邮箱的SMTP以前是非SSL,用未加密的25端口,后来发送都改成SSL了,端口为465或587( ...