Week 2
Lecture 2.2
Variables :-
Instructions for writing reader-friendly variables -
1. Make the variable self-explanatory.
2. Add comments.
For example :
Lecture 2.3
Dynamic Typing :-
In python, if you declare a variable as integer, it does not stay as integer ; you can
change the variable’s data type to whatever you want.
Python provides us flexibility to use variables.
,Another example of dynamic typing :-
Lecture 2.4
More on Variables, Operators and Expressions :-
In Python, there are some words like and, or, not, if, else, for, while,... which are referred
to as 'Keywords'.
We can not use these keywords as variable names.
For example :
Rules for writing variable names :-
1. Variable names can contain alphanumeric (all alphabets from A-Z in lower and
uppercase and numbers 0-9) characters and underscores.
, 2. We can start a variable name with an alphabet or an underscore but we cannot
start it with a number.
3. Variable names are case sensitive.
Even though the spellings are the same, the computer treats all three variables as
unique variables. This shows that in Python variable names are case sensitive.
Multiple Assignment :-
Note that the order matters. The following code assigns 1 to the variable x and 2 to the
variable y.
Lecture 2.2
Variables :-
Instructions for writing reader-friendly variables -
1. Make the variable self-explanatory.
2. Add comments.
For example :
Lecture 2.3
Dynamic Typing :-
In python, if you declare a variable as integer, it does not stay as integer ; you can
change the variable’s data type to whatever you want.
Python provides us flexibility to use variables.
,Another example of dynamic typing :-
Lecture 2.4
More on Variables, Operators and Expressions :-
In Python, there are some words like and, or, not, if, else, for, while,... which are referred
to as 'Keywords'.
We can not use these keywords as variable names.
For example :
Rules for writing variable names :-
1. Variable names can contain alphanumeric (all alphabets from A-Z in lower and
uppercase and numbers 0-9) characters and underscores.
, 2. We can start a variable name with an alphabet or an underscore but we cannot
start it with a number.
3. Variable names are case sensitive.
Even though the spellings are the same, the computer treats all three variables as
unique variables. This shows that in Python variable names are case sensitive.
Multiple Assignment :-
Note that the order matters. The following code assigns 1 to the variable x and 2 to the
variable y.