Python
Training Program
S V Ramanamurthy
Senior Vice President
CodeTantra Tech Solutions Pvt. Ltd.
Hyderabad
06/13/2021 RVRJCE - Python - Day 1 1
About The Speaker
9 years - New Zealand, Australia, Holland
8years - Australia
13 years – Oman
3 years – India, Singapore
8 years – India
06/13/2021 RVRJCE - Python - Day 1 2
Program details
Dates: 07-06-2021 to 26-06-2021 Time: 08:00AM to 10:00AM (10:30AM – 12:30PM)
No Topic
1 Introduction to Programming languages and problem solving process
2 Introduction to Python Data Types and Operators
3 Algorithmic Problem Solving + Control Statements
4 Numbers + Strings and String Functions
5 Data Structures - Lists, Tuples, Dictionaries, Sets
6 Comprehensions + Functions
7 Modules + Packages + File Handling
8 Object Oriented Programming in Python + Exception Handling
9 Advanced Topics (DB connectivity, Django, Advanced Data Structures)
10 Revision and Feedback
06/13/2021 RVRJCE - Python - Day 1 3
Why do we need a programming
language?
• To communicate with the computer
• Computers understand binary (machine) language
consisting of only 2 symbols 0 and 1
• Users understand Natural language
Machine
Natural Language
Language (binary)
(English) Which
Language ?
06/13/2021 RVRJCE - Python - Day 1 4
Why not English?
• English is ambiguous
• I am Ramana vs I am rich
• English is inconsistent
• Same word (e.g. well) has different meanings at different times
• English is context sensitive
• The meaning of a word or expression changes with context
• English is relative
• Come here etc.
• English is idiomatic – He kicked the bucket
06/13/2021 RVRJCE - Python - Day 1 5
Why not binary language?
• Too difficult to learn
• Remembering 256 ASCII code sequences
• Too lengthy
• For every letter 8 bits have to be used
06/13/2021 RVRJCE - Python - Day 1 6
Solution – Programming language
•Characteristics of a Program language
• Unambiguous
• Consistent
• Context free
• Absolute
06/13/2021 RVRJCE - Python - Day 1 7
Problem solving
• We use the programming language to write a program, which
executes on the computer to solve a problem.
• The problems can be of various types:
• Mathematical (Hanoi towers, Fibonacci numbers, Prime numbers, GCD,
factors of a number, polynomials etc.)
• Scientific (solar system simulation, simulation of various scientific processes)
• Real world (Hospital management, banking, Air traffic control, School /
college management etc.)
• All problems follow a simple pattern:
• Input Process Output
06/13/2021 RVRJCE - Python - Day 1 8
Problem solving - Examples
• Identify the input, process and output for the
following problems:
• Making Aloo Paratha
• Calculating the Average of a class (of n students)
• Printing the memorandum of marks for a student
• Calculating and printing the factors of a given number
• Checking whether a given number is prime or not
06/13/2021 RVRJCE - Python - Day 1 9
Problem solving - Mapping
Real world
INPUT PROCESS OUTPUT
Operators
Data types Data types
Statements
Computer
06/13/2021 RVRJCE - Python - Day 1 10
Problem solving - Mapping
• Examples: Identify the datatypes of the following real world attributes
• Age, population
• Salary
• Height, weight
• Name of a student
• Colours in rainbow
• Collection of names
• Collection of shopping items
• Collection of tastes
• Countries and capitals
• Solution for quadratic equation 4x2 + 8x + 53
06/13/2021 RVRJCE - Python - Day 1 11
Why Python?
User Friendly:
• Easy to understand
• Easy to learn
Flexible and Powerful:
• More like natural language
• Powerful constructs like decorators, comprehensions
Community
• most-used languages in the programming world,
• GitHub’s second-most used language for additions to repositories.
• 8th fastest growing language (2019), growing 151% over the year.
• preferred by a wide variety of educational institutions due to its easy learning curve, resulting in a lot of learning
material for beginners. The community is one of Python’s biggest strengths.
Libraries:
• Extensive libraries in all fields. These libraries are collections of code that offer easier ways to program complex
problems. These are at the basis of most specializations using Python, and machine learning is no exception.
06/13/2021 RVRJCE - Python - Day 1 12
Python Language
• Syntax and Grammar
• Data Types
• Operators
• Statements
• Functions
• OOPS concepts
• Exceptions
• Advanced features
06/13/2021 RVRJCE - Python - Day 1 13
Syntax and Grammar
• Identifiers
• Names of variables, functions, classes, modules etc.
• Keywords
• Indentation
• Comments
06/13/2021 RVRJCE - Python - Day 1 14
Syntax and Grammar - Identifiers
• Identifiers
• Should start with _ or alpha character
• Should contain only _ and alphanumeric characters
• Should not be a keyword
• Case sensitive
• Examples:
• Valid -> a1, _flag, __abc__, transaction_log,
• Invalid -> 1a, +flag, --abc--, tran#_log
• Valid but should not be used -> sum, len, max, min etc..
06/13/2021 RVRJCE - Python - Day 1 15
Syntax and Grammar - Keywords
• Keywords
• ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue',
'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return',
'try', 'while', 'with', 'yield’]
• Can get by typing
• Import keyword
• [Link]
• [Link](s) will return True if s is a keyword else returns
False
06/13/2021 RVRJCE - Python - Day 1 16
Syntax and Grammar - Indentation
• Indentation in Python refers to the (spaces and tabs) that are used at the beginning of a
statement. The statements with the same indentation belong to the same group called a
block or suite
• Example:
if a==1:
print(a) Inner Block
if b==2: Outer block
print(b) # Inner most block
print('end’)
• Indentation is very important in python. Incorrect indentation leads to syntax and run
time errors. You cannot mix tabs and spaces for indentation in the same program.
06/13/2021 RVRJCE - Python - Day 1 17
Syntax and Grammar - Comments
• Single line Comments in Python begin with a hash mark ( # ) and continue
to the end of the line.
• # This is line comment
• a = b+5 # This is a partial line comment
• Multiple line comments in python are enclosed in triple quotes (‘’’ or “””).
“”” This is a
multiline
comment “””
• Because comments do not execute, when you run a program you will not
see any indication of the comments during runtime. Comments are in the
source code for humans to read, not for computers to execute.
06/13/2021 RVRJCE - Python - Day 1 18
Syntax and Grammar – doc strings
• Python documentation strings (or docstrings) provide a convenient way of
associating documentation with Python modules, functions, classes, and
methods. It's specified in source code that is used, like a comment, to document
a specific segment of code. Python docstrings are strings used right after the
definition of a function, method, class, or module. They can be accessed during
run time by __doc__ attribute.
• Example:
def square(n):
“”” Takes a number as input and returns its square”””
return n**2
print(square.__doc__)
06/13/2021 RVRJCE - Python - Day 1 19
Homework
• Install python latest version (from [Link])
• Practice on IDLE
• Complete L1, L2 of CodeTantra Python course
06/13/2021 RVRJCE - Python - Day 1 20