Page 66 - Modular v1.1 Pyhton
P. 66

Membership Operators

                  Membership operators are used to check if a particular character exists in the given string or not.
                  There are two types of membership operators:

                      ‘in’ operator: It returns true if a characters/substring exist in the given string.
                      ‘not in’ operator: It returns true if a characters/substring does not exist in the given string.

                  Comparison Operators

                  Comparison operators (>, <, >=, <=, ==, !=) are used to compare two strings. It compares first

                  element from each sequence (character by character) and if they are equal then it goes on to the
                  next element until it finds elements that differ.
                  String Slicing


                  Chunks of characters can be extracted from a string by using slice operator [:]. Slice of a string is
                  a extracted substring.

                      PYTHON BUILT-IN FUNCTIONS

                  Python includes the following built-in functions to manipulate strings:
                      len( ): The len( ) function calculates and returns the length of a string supplied as an argument.
                      Syntax of using len( ) function is:

                          len(string_name)
                      lower( ): The lower( ) function converts all uppercase letters to lowercase.
                      Syntax of using lower( ) function is:

                          string_name.lower( )
                      upper( ): The upper( ) function converts all lowercase letters to uppercase.

                      Syntax of using upper( ) function is:
                          string_name.upper( )

                      capitalize( ): The capitalize( ) function returns a string with the first letter in capital.
                      Syntax of using capitalize( ) function is:
                          string_name.capitalize( )

                      count(): The count() function returns the number of times substring occurs in the given
                      string.

                      Syntax of using count() function is:
                          str.count(substring, start, end)
                      Program 8: To use various string built-in functions.











                   64     Touchpad MODULAR (Version 1.0)
   61   62   63   64   65   66   67   68   69   70   71