### Mutability in Python

• Mutability indicates whether the value can change after creation
• Basic memory allocation process
• If we are able to change the value after creation (without impacting memory ) then it is considered to mutable otherwise immutable
Name Type Mutable? Examples
Boolean bool no True, False
Integer int no 47, 45000
Floating Point float no 3.14, 2500.3
Text str no ‘python’, ‘ML’
• Note: In python we have a Garbage collector which will clean all the unused memory objects

### Copying

• assigning an existing variable a to new variable b just makes new variable b point to the same object that a does.
• If you either pick a or b and change any of the value & if the type is immutable
• Lets look at mutable type list

### Good Variable Names

• When ever we are creating variables try to give meaningful names
``````1. Creating a variable to store the favorite color
i = 'black' # not meaningful
fc = 'black' # not meaningful
favorite_color = 'black' # meaningful
``````
• Snake case
``````my_car
next_course
my_favorite_holiday_spot
``````
• Pascal case
``````MyCar
NextCourse
MyFavoriteHolidaySpot
``````
• Camel Case
``````myCar
nextCourse
myFavoriteHolidaySpot
``````
• In python to create variables we use snake case

### Numbers

• We will look into the following built in data types
• Booleans
• Integers
• Floats
• In python bool type has only two values True, False
• Lets look at how integers can be converted to bool’s
• operators that can be bool
• not
• and
• or
• In python int can hold integer values
• Lets look at some operator
Operator Description Example Result
Subtraction 7-5 2
* Multiplication 7*5 35
/ Floating point division 7/5 1.4
// Integer division (quotient) 7 //5 1
% Modulus (remainder) 7%5 2
** Exponentiation 2 ** 3 8
• Operator precedence: Refer Here
• To convert into integer use int() function
• How big is integer

### Exercise:

• Value of the following when calculate by python
• 5 * 2 – 3
• ( 100 – 5 **3 ) / 5
• 2 ** 2 + 24 // 4

### Spacing in Python

• We can write
``````5**3
``````
• But since Zen of python says readability counts
``````5 ** 3
``````

This site uses Akismet to reduce spam. Learn how your comment data is processed.