It was a memorandum because the content taught by the teacher was interesting. I just learned how to do it and verified it myself, so if you notice that it's wrong here, please let me know.
Feature -True if only str type numbers (integers). (0 is also True, but numbers starting with 0 are errors) -Even with str type numbers, negative numbers are False. (Is the minus considered a letter?) ・ A small number of str-type numbers are False. (False even if the decimal point is 0) ・ Even with str-type numbers, if letters and symbols are mixed, it will be False. (The operation symbol is also False) -For both str type and int type, numbers starting with 0 are SyntaxError. ・ ”Is False. -Characters are False. -Int type numbers are SyntaxError. (Including calculation results) -Numbers other than 0 that start with 0 are AttributeError regardless of the type.
’’’ print('1'.isdigit()) #True print('100'.isdigit()) #True print('0'.isdigit()) #True
print('a'.isdigit()) #False print('10.0'.isdigit()) #False print('2*3'.isdigit()) #False print(''.isdigit()) #False print('11a'.isdigit()) #False print('-1'.isdigit()) #False
print(1.isdigit()) # SyntaxError: invalid syntax print(5%3.isdigit()) # SyntaxError: invalid syntax print(3+4.isdigit()) #SyntaxError: invalid syntax
print(01.isdigit()) #SyntaxError: invalid character in identifier print('01'.isdigit()) #SyntaxError: invalid character in identifier
print('0.1'.isdigit()) # AttributeError: 'float' object has no attribute 'isdigit' print(0.1.isdigit()) # AttributeError: 'float' object has no attribute 'isdigit' ’’’
that's all.
Recommended Posts