[英]How can a Python string be a digit?
I was under the impression that numbers in double-quotation marks become strings.我的印象是双引号中的数字会变成字符串。 Why did I get the following result?为什么我得到以下结果?
"2001".isdigit()
True
.isdigit()
is a method for the str
object if this string only contains digits.如果此字符串仅包含数字,则.isdigit()
是str
对象的方法。
From the Python documentation , .isdigit()
:从Python 文档.isdigit()
:
Return true if all characters in the string are digits and there is at least one character, false otherwise.如果字符串中的所有字符都是数字并且至少有一个字符,则返回 true,否则返回 false。 Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits.数字包括十进制字符和需要特殊处理的数字,例如兼容性上标数字。 This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers.这涵盖了不能用于形成以 10 为基数的数字的数字,例如 Kharosthi 数字。 Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal.正式地,数字是具有属性值 Numeric_Type=Digit 或 Numeric_Type=Decimal 的字符。
It says .isdigit()
not .isint()
which makes sense since int
and string
are Python types, but nobody says a string can't be digits.它说.isdigit()
而不是.isint()
,这是有道理的,因为int
和string
是 Python 类型,但没有人说字符串不能是数字。
In fact, strings can contain letters, alphanumeric, digits, and a bunch of other things.事实上,字符串可以包含字母、字母数字、数字和一堆其他东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.