I was under the impression that numbers in double-quotation marks become strings. Why did I get the following result?
"2001".isdigit()
True
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.
From the Python documentation, .isdigit()
:
Return true if all characters in the string are digits and there is at least one character, false otherwise. 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. Formally, a digit is a character that has the property value Numeric_Type=Digit or 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.
In fact, strings can contain letters, alphanumeric, digits, and a bunch of other things.