INTRODUCTION TO
PYTHON
Python
High-level programming language
Interpreted
Interactive
Object-Oriented Programming Language
Why Python?
Easy to learn
Can be used in broad range of applications
Open source
Procedural, Functional, Object-Oriented
Evolution of Python
Developed by Guido Van Rossum in early 1990s
Named after a comedy group Monty Python
Features derived from many languages like C, C++,
Java and other scripting languages
Available under GNU General Public License
( Free, Open Source)
Features
Extensive Standard Library
Cross Platform Compatibility
Portable and Extendable
Databases and GUI Programming
Tokens
Tokens are the smallest elements of a program, which are
meaningful to the compiler.
Types of Tokens
Keywords
Identifiers
Operators
Delimiters
Keywords
Keywords are predefined, reserved words in Python
Each keyword is associated with specific features.
Keywords are case sensitive
Identifiers
Names given to anything that you want to
identify in a program.
Helps to refer to that item from any place in a
program
Identifiers
Rules to create an Identifier
Can contain letters in lower case (a-z), upper case (A-Z), digits (0-
9), and underscore ( _ )
Identifier name can’t begin with a digit
Never use special symbols like !, @, #, $, %, etc.,
Can’t contain only digits
Can start with an underscore
Identifier names are case sensitive
Identifiers
Example:
student_name
studentName
session1
1Age
564
_year
Delimiters
Delimiters are either grouping symbols, punctuation symbols, or
symbols that assign/bind objects to names
() [ ] { } Grouping
. , : ; Punctuation
+= -= *= /= Arithmetic assignment binding
(More in Operators)
Literals
Literals are the data that is used in the program.
Numbers
43, 32.67, 6 + 4.13j
Strings
‘example’, “Day One”, ‘‘‘another example’’’
Variables
Variable is an identifier used to refer a value in the program.
Variable is a name of the memory location. It is used to store
data.
Variable
Rules to define a Variable
Can contain letters in lower case (a-z), upper case (A-Z), digits (0-
9), and underscore ( _ )
Identifier name can’t begin with a digit
Never use special symbols like !, @, #, $, %, etc.,
Can’t contain only digits
Can start with an underscore
Identifier names are case sensitive
Declaring a Variable
Syntax: Random
Access
variablename = value Memory
day 100 1
Example:
day=1
Declaring a Variable
Syntax:
variablename = value
Example:
language=“Python”
day=1
usage =100.00
Deleting a Variable
Syntax:
del variablename
Example:
language=“Python”
del language
Input/Output Functions
Built-in functions used to perform Input/Output
operation in Python
Input operation:
To get the input from the user
Function Used:
input( )
Input/Output Functions
Input operation:
Syntax:
variablename= input([prompt ])
Ex:
name=input(“Enter your Name:”)
Enter your Name:
Input/Output Functions
Input operation:
Function Used:
input( )
All the inputs are considered as strings
Input/Output Functions
Output Operation:
To display the output
Function Used:
print( )
Input/Output Functions
Output operation:
Syntax:
print([output ])
Example code:
language=“Python”
print(language)
Output:
Input/Output Functions
Output operation:
Example code:
language=“Python”
print(‘You are learning ’,language)
Output:
You are learning Python
Input/Output Functions
input( ) All the inputs are considered as strings
Example code:
number1=input(“Enter a number:”)
number2=input(“Enter another number:”)
print(“Result:”,number1+number2)
Output:
Enter a number :5
Enter another number:6
Input/Output Functions
Example code:
number1=int(input(“Enter a number:”))
number2=int(input(“Enter another number:”))
print(“Result:”,number1+number2)
Output:
Enter a number :5
Enter another number:6
Formatting the Output
Example code:
session=“Session 1”
language=“Python”
print(session, language)
Output:
Session 1 Python
Formatting the Output
Example code:
print('This is an {0} for formatting the {1}'.format(‘example’, ‘output’))
Output:
This is an example for formatting the output
Formatting the Output
Example code:
session=“Session 1”
language=“Python”
print('This is {0}.You are learning {1}'.format(session,
language))
Output:
This is Session [Link] are learning Python
Comment Line
Comment is text in a program's code that is not meant to
be seen by the user running the program.
Comments help make code easier to understand by
explaining what is happening.
When the program is interpreted, the comment lines are
ignored.
Comment Line
Comment Line Representation
Single line comment (#)
Multiline comment (" ", ''' ''' )
Using Comment Line
Example code:
#variable declaration
name=“Ajay”
age = 18
'''printing the output
using the values stored in the variables'''
print(“Name :”, name)
print(“Age:”, age)
Output:
Name: Ajay
Age: 18