Which of the following functions cannot be used with string(str) data type?

2023

Which of the following functions cannot be used with string(str) data type?

  1. A.

    islower() / islower()

  2. B.

    isupper() / isupper()

  3. C.

    isalpha() / isalpha()

  4. D.

    isnum() / isnum()

Attempted by 1331 students.

Show answer & explanation

Correct answer: D

Answer: isnum() is not a valid string method in Python.

Explanation: The methods islower(), isupper(), and isalpha() are valid string methods. There is no built-in method named isnum(). To check whether a string contains numeric characters, use isnumeric(), isdigit(), or isdecimal() depending on the need.

  • islower(): Returns True if the string has at least one cased character and all such characters are lowercase. Example: "hello".islower() -> True

  • isupper(): Returns True if the string has at least one cased character and all such characters are uppercase. Example: "HELLO".isupper() -> True

  • isalpha(): Returns True if all characters are alphabetic and the string is non-empty. Example: "abc".isalpha() -> True; "abc123".isalpha() -> False

  • isnum(): This name is not a valid str method. Use isnumeric(), isdigit(), or isdecimal() to test numeric content. Example: "123".isnumeric() -> True

Therefore, the function that cannot be used with the string (str) data type is isnum().

Explore the full course: Rssb Senior Computer Instructor