isdigit() is an in-built method in Python, which is used to check whether a string contains only digits or not.

isdigit()是Python中的内置方法,用于检查字符串是否仅包含数字。

Digit value contains all decimal characters and other digits which may represent power or anything related to this, but it should be a complete digit, like "3".

数字值包含所有十进制字符和其他数字,这些数字可能表示幂或与此有关的任何东西,但它应该是完整的数字,例如“ 3”

This method is different from isdecimal() method and isnumeric() method because first method checks only decimal characters and second method checks numeric values including decimal characters. And this (isdigit()) method will consider only digit.

此方法不同于isdecimal()方法和isnumeric()方法,因为第一个方法仅检查十进制字符,第二个方法检查包括十进制字符的数值。 并且此( isdigit() )方法将仅考虑digit。

Note:

注意:

  • Digits value contains decimal characters and other Unicode digits, fractional part of the value like ½, ¼ etc are not considered as digit.

    数字值包含十进制字符和其他Unicode数字,该值的小数部分(如½,¼等)不视为数字。

  • String should be Unicode object - to define a string as Unicode object, we use u as prefix of the string value.

    字符串应为Unicode对象-要将字符串定义为Unicode对象,我们使用u作为字符串值的前缀。

Syntax:

句法:

    String.isdigit();

Parameter: None

参数:

Return type:

返回类型:

  • true - If all characters of the string are digits then method returns true.

    true-如果字符串的所有字符都是数字,则method返回true 。

  • false - If any of the characters of the string is not a digit then method returns false.

    false-如果字符串中的任何字符都不是数字,则方法返回false 。

Example/program:

示例/程序:

# Only digits (decimal characters)
str1 = u"362436"
print (str1.isdigit())
# digit value (no decimals but a digit)
str2 = u"3"
print (str2.isdigit())
# numeric values but not any digit
str3 = u"½¼"
print (str3.isdigit())
#digits, alphabets
str4 = u"Hello3624"
print (str4.isdigit())

Output

输出量

    True
True
True
False

Reference: String isdigit()

参考: 字符串isdigit()

翻译自: https://www.includehelp.com/python/string-isdigit-method-with-example.aspx

Python字符串| isdigit()方法与示例相关推荐

  1. 如何看待,入门学习Python必看视频?python字符串(string)方法整理

    如何看待,入门学习Python必看视频?哈佛大学教授推荐,python字符串(string)方法整理 哈佛大学推荐,Python基础入门,Python小白书籍,Python学习路线,Python进阶, ...

  2. python 字符串find方法怎么用_Python字符串find()方法

    Python字符串find()方法确定字符串str是出现在字符串中,还是在字符串指定范围的子串中,子字符串是由给给定起始索引beg和结束索引end切片得出. 语法 以下是find()方法的语法 - s ...

  3. Python字符串isdigit()

    Python String isdigit() function returns True if all the characters in the string are digits, otherw ...

  4. Python字符串--split方法

    Python字符串–split方法 描述: 这是字符串的分隔方法,主要有两个参数.第一个参数是"指定分隔符对字符串进行分隔",第二个参数是"指定分隔的段数",在 ...

  5. python的for语句写新的字符串_python写for循环python字符串排序方法

    一般情况下,python中对一个字符串排序相当麻烦: 一.python中的字符串类型是不允许直接改变元素的.必须先把要排序的字符串放在容器里,如list. 二.python中的list容器的sort( ...

  6. python的字符串定界符可以使用_使用Template格式化Python字符串的方法

    对Python字符串,除了比较老旧的%,以及用来替换掉%的format,及在python 3.6中加入的f这三种格式化方法以外,还有可以使用Template对象来进行格式化. from string ...

  7. python string 方法,python字符串的方法与操作大全

    一:字符串的方法与操作 *注意:首字母为l的为从左边操作,为r的方法为从右边操作 1.__contains__()判断是否包含 判断指定字符或字符串是否包含在一个字符串内,返回值为true或者fals ...

  8. python字符串反转方法_Python程序使用堆栈和反转方法反转字符串

    python字符串反转方法 Given a string and we have to reverse it by using stack and by using reversed method i ...

  9. “Python字符串index()方法应用案例”文末三道思考题答案

    问题链接:Python字符串index()方法应用案例一则 本文给出上文文末三个思考题的参考答案,当然,这些答案不是唯一的,也不是最高效的,只是演示字符串方法和内置函数的用法,并且在原题代码上做最少的 ...

  10. Python字符串对齐方法(ljust()、rjust()和center())详解

    Python字符串对齐方法(ljust().rjust()和center())详解 Python str 提供了 3 种可用来进行文本对齐的方法,分别是 ljust().rjust() 和 cente ...

最新文章

  1. Python 判断类型
  2. 【QwQ】乱七八糟的置顶
  3. python3.6安装pygame-Pygame 框架安装教程(Python3.6为例)
  4. Expression Design与Blend制作滚动的小球动画教程
  5. Centos:Yum常用参数
  6. Golang实践录:工程管理
  7. 今日头条反省整改;微信QQ封杀短视频;雷军10亿赌约将见分晓| CSDN极客头条
  8. linux任务计划不执行时间,Linux任务计划、周期性任务执行
  9. rk3399_android7.1的HDMI显示实现固定分辨率
  10. C语言实现学生信息管理系统
  11. Wireshark 使用教程
  12. struts2通配符使用
  13. html段落简字前带繁字,简繁体字对照表,抄佛经的师兄们必藏
  14. 浅析三点SEO理论到底带给了我们什么
  15. Jquery.ajax使用
  16. 基于Springboot开发实现买卖三方二手商品交易网站
  17. mysql 美东时间格式_C#/.NET怎么样将UTC时间转换成美国东部时间(EST)
  18. Centos7 安装RTL8723BE无线网卡驱动
  19. 分享我的33家公司面试经历(杭州华数/杭州网通/ 瞬联科技 )转贴
  20. stm32——手动移植HAL库以及错误解决方案(以STM32F103ZE为例)

热门文章

  1. Weblogic12c T3 协议安全漏洞分析【CVE-2020-14645 CVE-2020-2883 CVE-2020-14645】
  2. python邮箱爆破_Python在线爆破邮箱账号密码测试代码(亲测可用)
  3. linux 脚本批量删除,Linux Shell使用Bash脚本批量删除文件
  4. html5语义化标签 加粗,html5标签 H5标签
  5. java保留二位小数_java使double保留两位小数的多方法 java保留两位小数
  6. 【手把手 脑把脑】教会你使用idea基于MapReduce的统计数据分析(从问题分析到代码编写)
  7. 【实时+排重】摆脱渠道统计刷量作弊行为
  8. 性能测试调优篇---未完待续
  9. NEO从源码分析看共识协议
  10. 团队项目—第二阶段第三天