Page 268 - Computer Science Class 11 Without Functions
P. 268

>>> '+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()
              False
         >>> ''.isspace()
              False
        Note that the function call ''.isspace() yields False because the empty string does not contain even a single
        whitespace.
        ●  s.startswith(subStr): The method startswith(subStr) tests whether the string s starts with the string
           subStr, passed as a parameter. For instance, in the following example, the first and second function calls returned
           True and False, respectively, as 'unethical' starts with 'un' and not with 'ethical'.
         >>> 'unethical'.startswith('un')
              True
         >>> 'unethical'.startswith('ethical')
              False
         >>> 'hello'.startswith('')
              True
        Note that the function call  'hello'.startswith('')  yields True, because the null string is a prefix of every
        string and the expression '' + 'hello' yields  'hello'.
        ●  s.endswith(subStr): The  method  endswith(subStr)  tests  whether  the  string  s  ends  with  the  suffix
           subStr, passed as an argument. For example,.
         >>> 'ethically'.endswith('ally')
              True
         >>> 'Bibasha Nayak'.endswith('Bibasha  Nayak')
              False
        Note  that  in  the  function  call  'Bibasha Nayak'.endswith('Bibasha Nayak')  False,  as  the  string
        'Bibasha Nayak' contains an extra blank.
        ●  s.find(subStr): The method find(subStr) searches for the first occurrence of the given string subStr in the
           string s and  returns the  index of the first occurrence of the string passed as an argument. If the string subStr
           does not appear anywhere in the string s, the method find() returns -1 indicating the condition substring not
           found. For example,
         >>> colors = 'green, red, blue, red, red, green'
         >>> colors.find('red')

         266   Touchpad Computer Science-XI
   263   264   265   266   267   268   269   270   271   272   273