Mutability and immutability in python
- Mutability refers to ability to change the value of object in the same memory location, other wise its immutable.
- Example of immutable
x = 5
id(x) => 2285657135872
x += 1
x => 6
id(x) => 2285657140160
- Example of mutable
x = [1,2]
id(x) => 2285657135872
x.append(3)
x => [1,2,3]
id(x) => 2285657135872
Sequence data types continued
-
list is mutable and tuple is immutable.
-
Refer Here for list tutorial by programiz and Refer Here for tuple tutorial
-
Modifying lists
Range method
- Range in python is a generator which helps in creating a sequnence
range(start, end, step)
range(1,3) indirectly ==> 1,2
range(1,6,2) indirectly ==> 1,3,5
- range is used a lot with for. Any thing which works with for is called as
iterable
Hacker rank
- Ensure you have hacker rank developer account
