|
| 1 | +# if we have created some thing and then if we can change its content is known as mutable in python for example we can change |
| 2 | +# dictionary |
| 3 | +# list |
| 4 | +# set |
| 5 | +# example for list |
| 6 | +fruits = ['apple' , 'Banana' ,'Orange'] |
| 7 | +print(fruits) |
| 8 | +fruits[0] = 'Green Apple' |
| 9 | +# here the value is changed |
| 10 | +print(fruits) |
| 11 | +print(fruits[0]) |
| 12 | +# example for dictionary |
| 13 | +student = { |
| 14 | + "name" : 'ali', |
| 15 | + "age" : 21, |
| 16 | + #in javascript we call it object but in python we call it dictionary make sure the key in double quotes |
| 17 | +} |
| 18 | +print(student) |
| 19 | +student['age'] = 100 |
| 20 | +# here the dictionary is also changed |
| 21 | +print(student) |
| 22 | +# exampe of set |
| 23 | +our_set = {1,2,3,} |
| 24 | +our_set.add(8) |
| 25 | +our_set.remove(2) |
| 26 | +print(our_set) |
| 27 | +# ++++++++++++++++++++++ Immputeable |
| 28 | +# that never allow to change their content is know is immuteable |
| 29 | +# int , string , float , toupe |
| 30 | +# example for string |
| 31 | +father_name = 'M Sharif' |
| 32 | +print(father_name) |
| 33 | +# father_name[0] = 'Muhammad' |
| 34 | +print(father_name) |
| 35 | +# example for int and float |
| 36 | +roll_number = 1393 |
| 37 | +print(roll_number) |
| 38 | +# roll_number[0] = 9999 |
| 39 | +print(roll_number) |
| 40 | +# When you assign a new value to a variable, the variable’s reference is updated to point to the new object. |
| 41 | +# If the old object is no longer being used, Python's garbage collector will automatically remove it from memory |
| 42 | +x = 10 # here is the x is pointing to a value of 10 in the memory |
| 43 | +y = x # y have the same reference as the x have |
| 44 | +x = 15 # here we have new one value now the new reference |
| 45 | +print(x) |
| 46 | +print(y) # but the y still have the old reference |
0 commit comments