Page 313 - Computer Science Class 11 With Functions
P. 313

>>> msg2 = 'SuraiyaJabin'
             >>> msg2.isupper()
                 False
            As the string msg1 comprises all uppercase letters, when the method isupper() is applied to it, the method
            returns True. However, as string msg2 comprises a mix of uppercase and lowercase characters, when the method
            isupper() is applied to it, the method returns False.
            ●  s.islower(): The method islower() tests whether the string comprises only lowercase characters, For
              example,
             >>> msg1 = 'suraiyajabin'
             >>> msg1.islower()
                 True
             >>> msg2 = 'SuraiyaJabin'
             >>> msg2.islower()
                 False
            As the string msg1 comprises all lowercase letters, when the method islower()  is applied to it, the method
            returns True. However, since the string msg2 comprises a mix of uppercase and lowercase characters, when the
            method islower() is applied to it, the method returns False.
            ●  s.isalpha(): The method isalpha() checks whether a string comprises only alphabets, for example,
             >>> 'SuraiyaJabin'.isalpha()
                 True
             >>> 'Suraiya Jabin'.isalpha()
                 False
            In the first function call, the method isalpha() returned True as the string comprises only the alphabets of the
            English language. However, the second function call returned False because the string included a space.
            ●  s.isdigit(): The method isdigit() checks whether a string comprises only digits. For example,

             >>> '9898989898'.isdigit()
                 True
            The above function call returns True since the string '9898989898' is composed of digits only. However, the
            following function call returns False as the string includes the symbols + and -, apart from the digits.

             >>> '+91-9898989898'.isdigit()
                 False
            ●  s.isalnum(): A valid user name may be allowed to contain only alphabets and digits. The method isalnum()
              enables us to  check whether the username entered by a user comprises only alphabets and digits. For example,

             >>> userId = 'Prodyot123'
             >>> userId.isalnum()
                 True
             >>> password = 'secret@123'
             >>> password.isalnum()
                 False
            Note  that  the  first  function  call  userId.isalnum() returns  True as the string  userId  comprises  only
            alphabets and digits. However, password.isalnum() yields False as the string password includes a special
            character @.

            ●  s.isspace(): The method isspace() returns True if the string comprises only whitespace characters and
              False otherwise. For example,
             >>> '  '.isspace()
                 True
             >>> '            '.isspace()
                 True
             >>> ' \t\n'.isspace()
                 True
             >>> '  hello '.isspace()


                                                                                                       Strings   311
   308   309   310   311   312   313   314   315   316   317   318