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( )

  2. B.

    isupper( )

  3. C.

    isalpha( )

  4. D.

    isnum( )

Attempted by 1898 students.

Show answer & explanation

Correct answer: D

The function isnum() does not exist for Python strings. Python provides several methods to check numeric content, such as isdigit(), isdecimal(), and isnumeric().

isdecimal() checks for decimal digits (0–9) only. isdigit() includes digit characters, including some Unicode digits. isnumeric() is broader and includes numeric characters like fractions, superscripts, and other Unicode numerals.

For example, '123'.isdecimal() returns True, while 'Ⅻ'.isnumeric() returns True. However, isnum() is not a valid method and cannot be used.

Explore the full course: Rssb Senior Computer Instructor