Explanation:
๐น Line 1: Call print()
print("42".isdecimal())
Before print() displays anything, Python first evaluates:
"42".isdecimal()
๐น Step 1: Create the String
"42"
Python creates a string containing two characters.
Memory Representation
Index: 0 1
┌───┬───┐
Value: │ 4 │ 2 │
└───┴───┘
Notice that these are characters, not integer values.
๐น Step 2: Call the isdecimal() Method
"42".isdecimal()
The isdecimal() method checks whether every character in the string is a decimal digit (0–9).
General Syntax
string.isdecimal()
It returns:
True → If all characters are decimal digits and the string is not empty.
False → Otherwise.
๐น Step 3: Check Each Character
Python examines every character one by one.
First Character
'4'
Is '4' a decimal digit?
✅ Yes
Second Character
'2'
Is '2' a decimal digit?
✅ Yes
Since every character is a decimal digit, the result becomes:
True
๐น Step 4: Execute print()
Now Python executes:
print(True)
Output
True

0 Comments:
Post a Comment