0% found this document useful (0 votes)
19 views14 pages

Presentation 3'

Uploaded by

totalcrx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views14 pages

Presentation 3'

Uploaded by

totalcrx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

PYTHON PROGRAMMING

SUBMITTED TO:- SUBMITTED BY:-


MRS.CH.SWARNA LALITHA M.PRIYA[231FW01030]
ASST PROFESSOR OF PYTHON
K.VARSHITHA[231FW01035]
VFSTR.
SK.SADIK[231FW01055]

V.TEJASWI[231FW01069]
TOKEN:-

• The smallest unit/element in the python program/script is known as a Token or a


Lexical unit..
• Python has following Tokens:-
• ► Keywords
• ► Identifiers
• ► Literals
• ► Operators
• ► Punctuators
• KEYWORDS:-
• Keywords are the reserve words/pre-defined words/special
words
of python which have a special meaning for the interpreter.

IDENTIFIERS(USER DEFINED NAMES):-


Identifiers are the name given to the
different
programming elements like variables, objects, classes, functions, lists,
dictionaries etc.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy