Page 449 - ComputerScience_Class_11
P. 449

Output

                  Original value of x: 100
                  New value of x: 200




                 Characteristics of Immutable data types in Python
                 There are some characteristics of immutable data types in Python:
                 •  Unchangeable: Once created, their values cannot be changed.
                 •  Modification Creates New Object: Any change results in a new object being created.
                 •  Examples: int, float, str, tuple, bool, none.

                 •  Indexing and Slicing: Ordered immutable types like strings or tuples allow access but not modification.
                 •  Memory Efficient: Immutable objects are generally safer and use memory efficiently.


                              Let’s Revisit


                      ♦ A data type is a category that defines the kind of value a variable can store and the operations that can be performed on it.
                      ♦ A floating (float) is a numeric data type used to store numbers that contain a decimal point or fractional part.
                      ♦ A Boolean (bool) is a logical data type that holds only two possible values, True and False.
                      ♦ A string is a sequence data type in Python that stores a group of characters enclosed in single (' ') or double (" ") quotes.
                      ♦ Sequence data types in Python are collections of items that are stored in a particular order.
                      ♦ A set is a collection of unordered, unique and mutable elements in Python.



                                                              MIND DRILL




                      Solved Questions



                 A.  Tick ( ) the correct option.
                    1.  Select the data type used in Python to store whole numbers without a decimal part.
                       a.  Integer                                     b.  Float
                       c.  Complex                                     d.  Boolean
                    2.  Which sequence data type is enclosed in single or double quotes?
                       a.  List                                        b.  Tuple
                       c.  String                                      d.  Dictionary
                    3.  Mark the following is a correct example of a basic list?
                       a.  [1, 2, 3, 4]                                b.  {1, 2, 3, 4}
                       c.  (1, 2, 3, 4)                                d.  1, 2, 3, 4
                    4.  Choose the Python data type(s) that do not allow storing duplicate values.
                       a.  List                                        b.  Tuple
                       c.  Set                                         d.  Dictionary key
                    5.  Which symbol is used to define a dictionary in Python?
                       a.  []                                          b.  {}
                       c.  <>                                          d.  ()

                  Answers
                      1.  a    2.  c     3.  a     4.  c    5.  b




                                                                                               Data Types in Python  447
   444   445   446   447   448   449   450   451   452   453   454