3. PYTHON IDENTIFIER
An identifier is a name given to entities like class, functions,
variables, etc. It helps to differentiate one entity from another.
Rules for writing identifiers:
I. Identifiers can be a combination of letters in lowercase (a to z) or
uppercase (A to Z) or digits (0 to 9) or an underscore _. Names
like myClass, var_1 and print_this_to_screen, _hrs all are valid
example.
II. An identifier cannot start with a digit. 1 variable is invalid,
but variable1 is perfectly fine.
III. Keywords cannot be used as identifiers.
10/10/2021
MS.DEEPALI SHINKAR 3
4. KEYWORDS
10/10/2021
MS.DEEPALI SHINKAR 4
Every programming language has special reserved words,
or keywords, that have specific meanings and restrictions
around how they should be used.
Python keywords are the fundamental building blocks of any
Python program.
Python keywords are different from Python’s built-in functions
and types.
5. KEYWORDS
10/10/2021
MS.DEEPALI SHINKAR 5
Every programming language has special reserved words,
or keywords, that have specific meanings and restrictions
around how they should be used.
Python keywords are the fundamental building blocks of any
Python program.
Python keywords are different from Python’s built-in functions
and types.
6. GETTING THE LIST OF KEYWORDS IN THE
PROMPT
10/10/2021
MS.DEEPALI SHINKAR 6
7. KEYWORDS
Value Keywords: True, False, None.
Operator Keywords: and, or, not, in, is.
Import Keywords: import, from, as.
10/10/2021
MS.DEEPALI SHINKAR 7
8. OPERATOR KEYWORDS
Operator keyword : and will result into True only if both
the operands are True.
10/10/2021
MS.DEEPALI SHINKAR 8
A B A and B
True True True
True False False
False True False
False False False
9. OPERATOR KEYWORDS
Operator keyword : or will result into True only if any
operands are True.
10/10/2021
MS.DEEPALI SHINKAR 9
A B A and B
True True True
True False True
False True True
False False False
10. OPERATOR KEYWORDS
Operator keyword : not operator is used to invert the
truth value.
10/10/2021
MS.DEEPALI SHINKAR 10
A not A
True False
False True
11. IMPORT KEYWORD
Import keyword :as is used to create an object while importing a
module. It means giving a different name(user-defined) to a module
while importing it.
10/10/2021
MS.DEEPALI SHINKAR 11
12. IMPORT KEYWORD
Import keyword : from…… import is used to import
specific attributes or functions into the current
namespace.
10/10/2021
MS.DEEPALI SHINKAR 12
14. COMMENTS
Use of comments
• Comments can be used to explain Python code.
• Comments can be used to make the code more readable.
• Comments can be used to prevent execution when testing
code.
10/10/2021
MS.DEEPALI SHINKAR 14
15. COMMENT
In Python, we use the hash (#) symbol to start writing a comment.
It extends up to the newline character.
These triple quotes(‘’’ ‘’’) are generally used for multi-line strings.
But they can be used as multi-line comment as well.
Example : """This is also a
perfect example of
multi-line comments"""
10/10/2021
MS.DEEPALI SHINKAR 15
16. STATEMENT
Instructions that a Python interpreter can execute are called
statements.
For example, a = 1 is an assignment statement.
10/10/2021
MS.DEEPALI SHINKAR 16
17. MULTILINE STATEMENT
In Python, end of a statement is marked by a newline character. But we can make a
statement extend over multiple lines with the line continuation character ().
For example:
a = 1 + 2 + 3 +
4 + 5 + 6 +
7 + 8 + 9
This is explicit line continuation. In Python, line continuation is implied inside
parentheses ( ), brackets [ ] and braces { }. For instance, we can implement the above
multi-line statement as
a = (1 + 2 + 3 +
4 + 5 + 6 +
7 + 8 + 9)
Here, the surrounding parentheses ( ) do the line continuation implicitly. Same is the
case with [ ] and { }.
We could also put multiple statements in a single line using semicolons, as follows
a = 1; b = 2; c = 3
10/10/2021
MS.DEEPALI SHINKAR 17
18. GETTING USER INPUT
• While Python provides us with two inbuilt functions to read the
input from the keyboard.
input ( prompt )
raw_input ( prompt )
10/10/2021
MS.DEEPALI SHINKAR 18
19. INPUT FUNCTION
This function first takes the input from the user and then
evaluates the expression, which means Python automatically
identifies whether user entered a string or a number or list.
If the input provided is not correct then either syntax error or
exception is raised by python.
10/10/2021
MS.DEEPALI SHINKAR 19
20. WHAT ARE VARIABLES?
A variable is created the moment you first assign a
value to it.
Variables are containers for storing data values.
• Creating Python Variable :
Python has no command for declaring a variable.
10/10/2021
MS.DEEPALI SHINKAR 20
21. PYTHON VARIABLES - ASSIGN MULTIPLE
VALUES
Many Values to Multiple Variables:
Python allows you to assign values to multiple variables in one line.
One Value to Multiple Variables:
And you can assign the same value to multiple variables in one line.
Unpack a Collection
If you have a collection of values in a list, tuple etc. Python allows
you extract the values into variables. This is called unpacking.
10/10/2021
MS.DEEPALI SHINKAR 21