Presentation 3'
Presentation 3'
V.TEJASWI[231FW01069]
TOKEN:-
LITERALS:-
► Literals are the data items that have a fixed or constant value..
• OPERATORS:-
• Operators are the symbols or words that perform some
kind of operation on given values (operands) in an expression and
returns the result.
• PUNCTUATORS:-
Punctuators are the symbols that are used in
programming language to organize sentence structure, indicate the
rhythm and emphasis of expressions, statements and Program
Structure....
Common Punctuators are:- ‘ ‘’ “” # \ ( ) { } [ ] @ ,....
IDENTIFIERS IN PYTHON
• Identifier is a user-defined name given to a variable, function, class, module,
etc. The identifier is a combination of character digits and an underscore.
• They are case-sensitive i.e., ‘num’ and ‘Num’ and ‘NUM’ are three different
identifiers in python.
• It is a good programming practice to give meaningful names to identifiers to
make the code understandable.
• We can also use the Python string isidentifier() method to check whether a
string is a valid identifier or not.
RULES FOR NAMING PYTHON IDENTIFIERS:-
• It cannot be a reserved python keyword.
• It should not contain white space.
• It can be a combination of A-Z, a-z, 0-9, or underscore.
• It should start with an alphabet character or an underscore ( _ ).
• It should not contain any special character other than an underscore ( _ ).
EXAMPLES OF PYTHON IDENTIFIERS:-
• Valid identifiers:-
• var1
• _var1
• _1_var
• var_1
INDENTATION OF PYTHON:-
• Indentation in Python is used to create a group of statements that are executed
as a block. Many popular languages such as C, and Java uses braces ({ }) to
define a block of code, and Python uses indentation.
• Indentation in Python refers to the whitespaces at the start of the line to indicate
a block of code. We can create an indentation using space or tabs. When writing
Python code, we have to define a group of statements for functions and loops.
This is done by properly indenting the statements for that block.
EXAMPLE:-
Def foo():
print(“Hi”)
if True:
print(“true”)
else:
print(“false”)
• print(“Done”)
PYTHON INDENTATION RULES:-
• The first line of Python code can’t have an indentation, it will throw
IndentationError.
• You should avoid mixing tabs and whitespaces to create an indentation. It’s
because text editors in Non-Unix systems behave differently and mixing them
can cause the wrong indentation.
• It is preferred to use whitespace than the tab character.
• The best practice is to use 4 whitespaces for the first indentation and then keep
adding additional 4 whitespaces to increase the indentation.
BENEFITS OF INDENTATION IN PYTHON:-
Indentation is important to increase the readability of the code by clearly indicating
the hierarchy (i.e. If statements belong to the same block or not).
This avoids the need to use delimiters such as braces or brackets, which is
mandatory in most programming languages like C, C++, Java, etc.
• Python indentation is consistent throughout the program, making it easier to
debug.
DISADVANTAGES OF INDENTATION IN PYTHON:-
Since whitespaces are used for indentation, if the code is large and indentation is
corrupted then it’s really tedious to fix it. It happens mostly by copying the code
from online sources, Word documents, or PDF files.
• Most of the popular programming languages use braces for indentation, so
anybody coming from a different programming world finds it hard at first to adjust
to the idea of using whitespaces for indentation