Page 388 - Ai_417_V3.0_C9_Flipbook
P. 388

A multiline string in Python is a string that spans across multiple lines. It allows you to create a string that contains
                    line breaks and multiple paragraphs without using special characters like \n for newline. Multiline strings are
                    defined by enclosing the text within triple quotes, either single (''') or double (""") quotes. For example,

                          '''It is
                          an interesting
                               Language'''

                    ✶ Lists: It is a sequence of heterogeneous values arranged as elements and are referred by an index number. These
                    values are separated by comma and are enclosed in square brackets [ ]. They are mutable data types as the
                    values of these data types can be changed by the user after creation. For example,

                          list_of_names=["Amit","Shweta","Peter","Zoya"]
                          Marks=[89,92,93,78,89]
                          class9=[101,"Neha",89.5,102,"Shushil",92]
                    ✶ Tuples:  It  is  a  sequence  of  heterogeneous  values  arranged  as  elements  and  are  referred  by  an  index
                    number. These values are separated by comma and are enclosed in circular brackets ( ). They are immutable
                    as the values of these data types cannot be changed by the user after creation.

                          mytuple=("Amit","Shweta","Peter","Zoya")
                          Marks=(89,92,93,78,89)
                          class9=(101,"Neha",89.5,102,"Shushil",92)
                 • Set:  A  set  is  a  collection  of  unique  elements  that  is  both  mutable  and  unordered.  Sets  are  defined  using
                 curly  brackets  {}  with  elements  separated  by  commas.  Each  element  in  a  set  must  be  unique.  Sets  are
                 commonly  used  for  tasks  that  involve  mathematical  operations  like  union,  intersection,  and  difference.
                 For example,
                 mySet = {21, 52, 33, 54, 95}
                 • Dictionary: In Python, a dictionary is a data type that stores a collection of Key : Value pairs. Each key is unique
                 within the dictionary, and it maps to a corresponding value. Dictionary is represented by curly braces {} with
                 each pair separated by a colon (:). Dictionaries are mutable, meaning they can be modified after creation.
                 For example, person = {'name': 'Yash', 'Department': 'Sales', 'city': 'Delhi'}

              Data Type Conversion

              The process of converting value of one data type to another is called type conversion or type casting. This is
              useful when you need to perform operations involving mixed types.

              Python supports two types of type conversion:
              1.   Implicit Type Conversion

              2.   Explicit Type Conversion
              1.    Implicit Type Conversion: In implicit type conversion, when Python encounters mixed data types, it
                 automatically converts one data type to another data type to avoid data loss and ensure compatibility. This
                 process doesn't require any user involvement.

                   # Example of implicit type conversion
                   a = 5                        # Integer
                   b = 2.0                     # Float

                   # Adding an integer and a float
                   result = a + b
                    386     Touchpad Artificial Intelligence (Ver. 3.0)-IX
   383   384   385   386   387   388   389   390   391   392   393