Page 448 - ComputerScience_Class_11
P. 448

Program 15: To display the mutable data types in Python.
                   Program 15.py

                File  Edit  Format   Run   Options   Window    Help

                # Create a set of subjects
                Subjects = {"Hindi", "English", "Math", "Hindi", "Science"}
                # Display the set
                print(Subjects)





                   Output

                {'Hindi', 'English', 'Science', 'Math'}




              Characteristics of Mutable data types in Python
              There are some characteristics of mutable data types in Python:
              •  Changeable: Their values can be modified after creation.
              •  Add, Update, Delete Elements: You can add new items, remove existing ones or update values.

              •  Examples: Set.
              •  Indexing and Slicing: Ordered mutable types like lists allow access and modification using indexes.
              •  Dynamic Size: The number of elements can grow or shrink over time.

              12.8.2 Immutable Data Types
              An immutable object in Python is an object whose value cannot be changed after it is created. Once you assign a value
              to it, you cannot modify the same object. If you try to change it, Python creates a new object instead of modifying the
              original one. Immutable objects can also be heterogeneous, which means they can store elements of different data
              types, such as numbers, strings and Boolean values (for example, a tuple).
              Program 16: To display the immutable data types in Python.

                   Program 16.py

                File  Edit  Format   Run   Options   Window    Help
                # Assigning an integer value to variable x
                x = 100
                # Printing the original value of x
                print("Original value of x:", x)
                # Reassigning a new integer value to x
                x = 200
                # Printing the new value of x
                print("New value of x:", x)










                  446  Touchpad Computer Science (Ver. 3.0)-XI
   443   444   445   446   447   448   449   450   451   452   453