KnowledgeBoat Logo
|

Computer Science

Assertion (A): The following code snippet on execution shall return the output as: False True

str1 "Mission 999"  
str2 = "999"  
print(str1.isdigit(), str2.isdigit())

Reasoning (R): isdigit() function checks for the presence of all the digits in an inputted string.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Python String Manipulation

1 Like

Answer

Both A and R are true and R is the correct explanation of A.

Explanation
The isdigit() function returns True if the string contains only digits, otherwise False. In the given code, str1 contains both alphabets and digits, so str1.isdigit() will return False. On the other hand, str2 contains only digits, so str2.isdigit() will return True.

Answered By

3 Likes


Related Questions