yasamanshamsizadeh / Python_practice

0 stars 0 forks source link

mutable & immutable #2

Open yasamanshamsizadeh opened 6 years ago

yasamanshamsizadeh commented 6 years ago

I want to learn everything about mutable & immutable

yasamanshamsizadeh commented 6 years ago

Everything in Python is an object . You have to understand that Python represents all its data as objects. An object’s mutability is determined by its type. Some of these objects like lists and dictionaries are mutable , meaning you can change their content without changing their identity. Other objects like integers, floats, strings and tuples are objects that can not be changed. List is mutable Mutable example: x=[1,3,5] x[0]=9 print(x) output: [9,3,5] Immutable are quicker to access than mutable objects. Also, immutable objects are fundamentally expensive to "change", because doing so involves creating a copy. Changing mutable objects is cheap.