Page 137 - TP_Prime_v2.2_Class_6
P. 137

Sets

                 Set is a mutable, unordered collection of values, of any type, with no duplicate element.

                   Sequence


                 A sequence is an ordered collection of items of similar or different data types. The three
                 types of sequence data types are Strings, Lists and Tuples.


                 Strings                                                                                                     INTRODUCTION TO PYTHON
                 A string is a sequence of one or more characters put in single quotes, double quotes or

                 triple quotes which are used to represent text-based information. The quotes are not a
                 part of the string.


                 List
                 A list is a collection of data elements separated by comma(,) and enclosed within square                 135

                 brackets. We can also create a list with the same or different data elements.

                 Tuple

                 A tuple is just like a list. It contains a group of elements that can be of different data
                 types. The elements in the tuple are separated by a comma and enclosed in parentheses
                 (). The difference between list and tuple is that list can be modified but tuples cannot be

                 modified after it is created.

                   Boolean


                 Boolean is a data type with two built in values: True or False. They are used for logical
                 evaluation. A True statement returns value 1 while a False statement returns value 0.


                    Using Separators with print( ) Function


                 In Python, separators are used to define how multiple items are separated when printed

                 or displayed. The print() function uses the sep parameter to control what separates the
                 items. By default, Python separates multiple values with a space. Below are the examples

                 of few separators:

                  Comma (,):

                 When we use a ‘,’ separator between the values in print( ) function, the values are printed

                 with a space between them.
   132   133   134   135   136   137   138   139   140   141   142