博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python字符串| isdigit()方法与示例
阅读量:2529 次
发布时间:2019-05-11

本文共 1668 字,大约阅读时间需要 5 分钟。

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 and because first method checks only decimal characters and second method checks numeric values including decimal characters. And this (isdigit()) method will consider only digit.

此方法不同于和因为第一个方法仅检查十进制字符,第二个方法检查包括十进制字符的数值。 并且此( 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 digitstr3 = u"½¼"print (str3.isdigit())#digits, alphabetsstr4 = u"Hello3624"print (str4.isdigit())

Output

输出量

True    True    True    False

Reference:

参考:

翻译自:

转载地址:http://votzd.baihongyu.com/

你可能感兴趣的文章
My安卓知识6--关于把项目从androidstudio工程转成eclipse工程并导成jar包
查看>>
旧的起点(开园说明)
查看>>
生产订单“生产线别”带入生产入库单
查看>>
crontab导致磁盘空间满问题的解决
查看>>
java基础 第十一章(多态、抽象类、接口、包装类、String)
查看>>
Hadoop 服务器配置的副本数量 管不了客户端
查看>>
欧建新之死
查看>>
自定义滚动条
查看>>
APP开发手记01(app与web的困惑)
查看>>
笛卡尔遗传规划Cartesian Genetic Programming (CGP)简单理解(1)
查看>>
mysql 日期时间运算函数(转)
查看>>
初识前端作业1
查看>>
为啥程序会有bug?
查看>>
跨域技术
查看>>
JS里的居民们7-对象和数组转换
查看>>
计算两个日期的时间间隔,返回的是时间间隔的日期差的绝对值.
查看>>
python初体验
查看>>
配置vue,vue脚手架的应用(老版本)
查看>>
linux下防火墙iptables原理及使用
查看>>
经典C面试真题精讲
查看>>