SlideShare a Scribd company logo
PYTHON BASICS
A. PERIYA NAYAKI,
ASSISTANT PROFESSOR,
KAMARAJ COLLEGE OF ENGINEERING
AND TECHNOLOGY,
MADURAI
• Python is a high level, interpreted , interactive and
object-oriented scripting language.
• It is a highly readable language.
• Unlike other programming languages, python provides
an interactive mode similar to that of a calculator.
PYTHON OVERVIEW
• The code written in python is automatically
compiled to byte code and executed.
• Python can be used as a scripting language.
• Features such as nested code blocks, functions,
classes, modules and packages.
• It make use of object-oriented programming
approach.
CONSOLE or COMMAND SHELL
The interactive environment where we are
interacting with the python interpreter is
called the console or command shell.
Practice
Now, try to interact with the interpreter by
entering a simple expression, 5+2, on the
console
Print Statement
The print statement is used to display the output
to the screen
Practice
Now, type the following text at the python prompt
Note: If you want to display a message on the console,
you will need to keep your message within quotes.
Print “Hi Friends, Welcome to Python Laboratory”
Or
Print ‘Hi Friends, Welcome to Python Laboratory’
COMMENTS
• It is used by the programmer to explain the piece
of code to others as well as to himself in a simple
language.
• Python uses the hash character (#) for
comments.
Practice
>>>5+2 #addition
PYTHON IDENTIFIERS
• A python identifier is the name given to a
variable, function, class, module or other
object.
• It can include any number of letters, digits or
underscores
• Spaces are not allowed
• It will not accept @, $,% as identifiers
• Python is a case-sensitive language.
• Hello and hello are different identifiers.
VALID NOT VALID
MyName My Name (Space is not allowed)
My_Name 3dig (cannot start with a digit)
Your_Name Your#Name (Only alphabetic character,
Underscore(_) and numeric are allowed)
VARIABLES
1. Declaring a Variable
2. Initializing a Variable
Declaring a Variable
• A variable holds a value that may change.
• The process of writing the variable name is called Declaring the
variable.
• In Python, variables do not need to be declared explicitly in order
to reserve memory spaces as in other programming languages.
• When we initialize the variable in python, python interpreter
automatically does the declaration process.
Initializing a Variable
• The general format of assignment statement is as follows:
• Equal sign (=) is known as assignment operator.
• An expression is any value, text or arithmetic expression
• Variable is the name of the variable.
• The value of the expression will be stored in the variable
Variable = expression
Practice
>>> Year=2017
>>> Department = ‘CSE’
Practice
>>>Department = ‘CSE’
>>> Dept=Department
>>>Dept
Practice
>>>Department = ‘CSE’
>>>Department = ‘ECE’
>>>Department
Standard Data Types
• The data stored in the memory can be of
many types.
• Example:
PERSON
NAME
ADDRESS
AGE >20
Alphabetic
Alphanumeric
Yes or No
(Boolean)
Data Types
Python Data Types
Numeric String List Tuple Dictionary Boolean
Numeric
• Broadly divided into Integers and Real
Numbers (i.e., Fractional Numbers or floating
point numbers (Fractional Part and Decimal
Part)).
Practice
>>>num1=2 #integer number
>>> num2=2.5 #real number(float)
>>>num1
>>>num2
String
• Single quotes or double quotes are used to
represent strings
• A string in python can be a series or a
sequence of alphabets, numerals and special
characters.
• Similar to C, the first character of a string has
an index 0.
• Slice Operator ([] and [:]) –Subset of the string
• Concatenation Operator (+) – Combine two or
more than two strings
• Repetition Operator (*) - Repeat the same
string several times
Practice
>>> string1=“Hi Friends” # Store String Value
>>>string1 # display string value
>>> string1 + “How are You” #use of + operator
>>> string1 *2 #use of * operator
Practice
>>>string1
>>>string1[1] #display 1st index element
>>>string1[0:2] #display 0 to 1st index element
>>>string1=“HelloWorld”
>>>string1[1:8:2]
#display all the alternate characters
between index 1 to 8
LIST
• List is the most used data type in python.
• It can contain the same or different type of
items.
• To declare a list in python->Separate items
using commas and enclose them within
square brackets([])
Practice
>>>first=[1,”two”,3.0,”four”] #1st list
>>>second=[“five”,6] #2nd list
>>>first
>>>first+second # concatenate 1st and 2nd list
>>>second*3 #repeat 2nd list
>>>first[0:2] #display sublist
Tuple
• Similar to a list, tuple is also used to store
sequence of items.
• Like a list, a tuple consists of items separated
by commas.
• Tuples are enclosed within parentheses
Practice
>>>third=(7,”eight”,9,10.0)
>>>third
Difference between tuple and list
LIST Tuple
Items are enclosed within square
brackets[]
Items are enclosed within parentheses ()
Lists are mutable Tuples are immutable
Practice
>>>first[0]=“one”
>>>third[0]=“seven”
Dictionary
• It is same as the hash table type.
• The order of elements in a dictionary is
undefined
• Unordered collection of key-value pairs.
• When we have large amount of data, the
dictionary data type is used.
• Keys and values can be of any type in
dictionary
• Items in dictionaries are enclosed in the curly-
braces {}
• Separated by the comma (,)
• A colon is used to separate key from value
• A key inside the square bracket [] is used for
accessing the dictionary items.
Practice
>>>dict1={1:”first”,”second”:2} #declare
dictionary
>>>dict1[3]=“third line” #add new item
>>>dict1
>>>dict1.keys() # display dictionary keys
>>>dict1.values() # display dictionary values
Boolean
The True and False data is known as Boolean
Data and data types which stores this boolean
data known as Boolean Data types
Practice
>>>a=TRUE
>>>type(a)
>>>b=FALSE
>>>type(b)
SETS
• It is an unordered collection of data known as
set.
• It does not contain any duplicate values or
elements.
• Union, Intersection, Difference and Symmetric
Difference  Operations which are performed
on sets
• Union (|): It performs on two sets returns all
the elements from both the sets.
• Intersection (&) : It performs on two sets
returns all the elements which are common in
both the sets
• Difference (-): It performs on two sets set1
and set2 returns the elements which are
present in set1 but not in set2.
• Symmetric Difference (^): It performs on two
sets returns the element which are present in
either set1 or set2 but not in both.
Practice
#Defining sets
>>>grp1=set([1,2,4,1,2,8,5,4])
>>>grp22=set([1,9,3,2,5])
>>>grp1 # printing set1
>>>grp2 #printing set2
Practice
>>>intersection = grp1 & grp2 #intersection
>>>intersection
>>>union=grp1 | grp2 # Union of grp1 & grp2
>>>union
>>>difference=grp1-grp2
>>>sym_diff = grp1 ^ grp2
Type() function
type() function is a built-in function which
returns the datatype of an arbitrary object.
Practice
>>>x=10
>>>type(x)
>>>type(‘hello’)
>>>import os
>>>type(os)
>>>t=(1,2,3)
>>>type(t)
>>>li=[1,2,3]
>>>type(li)
INPUT FROM KEYBOARD
1. input()
2. raw_input()
Input() function
• Input() function interprets the input provided
by the user, i.e. if user provides an integer
value as input then the input function will
return its integer value.
• On the other hand, if the user has input a
string, the function will return a string
Practice
>>>name = input(“What is your name?”)
>>>print (“Hello”+name)
>>>age=int(input(“Enter your age?”))
>>>age
>>>hobbies=input(“What are your hobbies?”)
>>>hobbies
Practice
>>>type(name)
>>>type(age)
>>>type(hobbies)
Raw_input() function
• It takes the input from the user but it does not
interpret the input and also it returns the
input of the user without doing any changes,
i.e. raw.
• Then, we can change this raw input into any
data type which is needed for our program.
Practice
# No casting
>>>age=raw_input(“Enter your age?”)
>>>type(age)
#Using type casting function to convert input to
integer
>>>age=int(raw_input(“What is your age?”))
>>>type(age)
End…

More Related Content

PDF
“Vitis and Vitis AI: Application Acceleration from Cloud to Edge,” a Presenta...
PPTX
Deep learning
PDF
Foundations of Machine Learning
PPTX
Random Number Generation
PPTX
Introduction to Python Programing
PPTX
Quantum machine learning basics
PPTX
Explainable AI - Posters
PDF
Seldon: Deploying Models at Scale
“Vitis and Vitis AI: Application Acceleration from Cloud to Edge,” a Presenta...
Deep learning
Foundations of Machine Learning
Random Number Generation
Introduction to Python Programing
Quantum machine learning basics
Explainable AI - Posters
Seldon: Deploying Models at Scale

What's hot (20)

PDF
Deep Learning With Python Tutorial | Edureka
PPTX
Analysing EEG data using MATLAB
PPTX
Deep learning presentation
PDF
Quantum Computers PART 1 & 2 by Prof Lili Saghafi
PPT
X.509 Certificates
PDF
Python 2 vs. Python 3
PDF
Recurrent Neural Networks, LSTM and GRU
PPTX
Introduction to Deep learning
PPTX
What is Deep Learning?
PDF
OpenAI’s GPT 3 Language Model - guest Steve Omohundro
PPT
Classical Encryption Techniques
PPTX
Superscalar Processor
PPTX
Emotion recognition and drowsiness detection using python.ppt
PPTX
Linkers in compiler
PPTX
Reverse Engineering.pptx
PDF
DeepFake Detection: Challenges, Progress and Hands-on Demonstration of Techno...
PDF
Deep learning seminar report
PPTX
INSTRUCTION LEVEL PARALLALISM
PPTX
Intro to deep learning
PPTX
Spam email detection using machine learning PPT.pptx
Deep Learning With Python Tutorial | Edureka
Analysing EEG data using MATLAB
Deep learning presentation
Quantum Computers PART 1 & 2 by Prof Lili Saghafi
X.509 Certificates
Python 2 vs. Python 3
Recurrent Neural Networks, LSTM and GRU
Introduction to Deep learning
What is Deep Learning?
OpenAI’s GPT 3 Language Model - guest Steve Omohundro
Classical Encryption Techniques
Superscalar Processor
Emotion recognition and drowsiness detection using python.ppt
Linkers in compiler
Reverse Engineering.pptx
DeepFake Detection: Challenges, Progress and Hands-on Demonstration of Techno...
Deep learning seminar report
INSTRUCTION LEVEL PARALLALISM
Intro to deep learning
Spam email detection using machine learning PPT.pptx
Ad

Similar to Python lab basics (20)

PPTX
Python_IoT.pptx
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
PPTX
1. python programming
PPTX
Python Basics by Akanksha Bali
PPT
Python programming
PPTX
Python unit 2 is added. Has python related programming content
PPT
01-Python-Basics.ppt
PPTX
Python for Beginners(v1)
PDF
software construction and development.pdf
PDF
"Automata Basics and Python Applications"
PPTX
Advance Python programming languages-Simple Easy learning
PPT
Python Programming Basic , introductions
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPSX
Programming with Python
Python_IoT.pptx
Basic concept of Python.pptx includes design tool, identifier, variables.
1. python programming
Python Basics by Akanksha Bali
Python programming
Python unit 2 is added. Has python related programming content
01-Python-Basics.ppt
Python for Beginners(v1)
software construction and development.pdf
"Automata Basics and Python Applications"
Advance Python programming languages-Simple Easy learning
Python Programming Basic , introductions
Python basics
Python basics
Python basics
Python basics
Python basics
Python basics
Python basics
Programming with Python
Ad

Recently uploaded (20)

PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Geodesy 1.pptx...............................................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
web development for engineering and engineering
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
composite construction of structures.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
DOCX
573137875-Attendance-Management-System-original
PPT
Mechanical Engineering MATERIALS Selection
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
additive manufacturing of ss316l using mig welding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Geodesy 1.pptx...............................................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
web development for engineering and engineering
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
composite construction of structures.pdf
CH1 Production IntroductoryConcepts.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT 4 Total Quality Management .pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
573137875-Attendance-Management-System-original
Mechanical Engineering MATERIALS Selection
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Lecture Notes Electrical Wiring System Components
additive manufacturing of ss316l using mig welding

Python lab basics

  • 1. PYTHON BASICS A. PERIYA NAYAKI, ASSISTANT PROFESSOR, KAMARAJ COLLEGE OF ENGINEERING AND TECHNOLOGY, MADURAI
  • 2. • Python is a high level, interpreted , interactive and object-oriented scripting language. • It is a highly readable language. • Unlike other programming languages, python provides an interactive mode similar to that of a calculator.
  • 3. PYTHON OVERVIEW • The code written in python is automatically compiled to byte code and executed. • Python can be used as a scripting language. • Features such as nested code blocks, functions, classes, modules and packages. • It make use of object-oriented programming approach.
  • 4. CONSOLE or COMMAND SHELL The interactive environment where we are interacting with the python interpreter is called the console or command shell.
  • 5. Practice Now, try to interact with the interpreter by entering a simple expression, 5+2, on the console
  • 6. Print Statement The print statement is used to display the output to the screen
  • 7. Practice Now, type the following text at the python prompt Note: If you want to display a message on the console, you will need to keep your message within quotes. Print “Hi Friends, Welcome to Python Laboratory” Or Print ‘Hi Friends, Welcome to Python Laboratory’
  • 8. COMMENTS • It is used by the programmer to explain the piece of code to others as well as to himself in a simple language. • Python uses the hash character (#) for comments.
  • 10. PYTHON IDENTIFIERS • A python identifier is the name given to a variable, function, class, module or other object. • It can include any number of letters, digits or underscores • Spaces are not allowed • It will not accept @, $,% as identifiers
  • 11. • Python is a case-sensitive language. • Hello and hello are different identifiers. VALID NOT VALID MyName My Name (Space is not allowed) My_Name 3dig (cannot start with a digit) Your_Name Your#Name (Only alphabetic character, Underscore(_) and numeric are allowed)
  • 12. VARIABLES 1. Declaring a Variable 2. Initializing a Variable
  • 13. Declaring a Variable • A variable holds a value that may change. • The process of writing the variable name is called Declaring the variable. • In Python, variables do not need to be declared explicitly in order to reserve memory spaces as in other programming languages. • When we initialize the variable in python, python interpreter automatically does the declaration process.
  • 14. Initializing a Variable • The general format of assignment statement is as follows: • Equal sign (=) is known as assignment operator. • An expression is any value, text or arithmetic expression • Variable is the name of the variable. • The value of the expression will be stored in the variable Variable = expression
  • 16. Practice >>>Department = ‘CSE’ >>> Dept=Department >>>Dept
  • 18. Standard Data Types • The data stored in the memory can be of many types. • Example: PERSON NAME ADDRESS AGE >20 Alphabetic Alphanumeric Yes or No (Boolean)
  • 19. Data Types Python Data Types Numeric String List Tuple Dictionary Boolean
  • 20. Numeric • Broadly divided into Integers and Real Numbers (i.e., Fractional Numbers or floating point numbers (Fractional Part and Decimal Part)).
  • 21. Practice >>>num1=2 #integer number >>> num2=2.5 #real number(float) >>>num1 >>>num2
  • 22. String • Single quotes or double quotes are used to represent strings • A string in python can be a series or a sequence of alphabets, numerals and special characters. • Similar to C, the first character of a string has an index 0.
  • 23. • Slice Operator ([] and [:]) –Subset of the string • Concatenation Operator (+) – Combine two or more than two strings • Repetition Operator (*) - Repeat the same string several times
  • 24. Practice >>> string1=“Hi Friends” # Store String Value >>>string1 # display string value >>> string1 + “How are You” #use of + operator >>> string1 *2 #use of * operator
  • 25. Practice >>>string1 >>>string1[1] #display 1st index element >>>string1[0:2] #display 0 to 1st index element >>>string1=“HelloWorld” >>>string1[1:8:2] #display all the alternate characters between index 1 to 8
  • 26. LIST • List is the most used data type in python. • It can contain the same or different type of items. • To declare a list in python->Separate items using commas and enclose them within square brackets([])
  • 27. Practice >>>first=[1,”two”,3.0,”four”] #1st list >>>second=[“five”,6] #2nd list >>>first >>>first+second # concatenate 1st and 2nd list >>>second*3 #repeat 2nd list >>>first[0:2] #display sublist
  • 28. Tuple • Similar to a list, tuple is also used to store sequence of items. • Like a list, a tuple consists of items separated by commas. • Tuples are enclosed within parentheses
  • 30. Difference between tuple and list LIST Tuple Items are enclosed within square brackets[] Items are enclosed within parentheses () Lists are mutable Tuples are immutable
  • 32. Dictionary • It is same as the hash table type. • The order of elements in a dictionary is undefined • Unordered collection of key-value pairs. • When we have large amount of data, the dictionary data type is used. • Keys and values can be of any type in dictionary
  • 33. • Items in dictionaries are enclosed in the curly- braces {} • Separated by the comma (,) • A colon is used to separate key from value • A key inside the square bracket [] is used for accessing the dictionary items.
  • 34. Practice >>>dict1={1:”first”,”second”:2} #declare dictionary >>>dict1[3]=“third line” #add new item >>>dict1 >>>dict1.keys() # display dictionary keys >>>dict1.values() # display dictionary values
  • 35. Boolean The True and False data is known as Boolean Data and data types which stores this boolean data known as Boolean Data types
  • 37. SETS • It is an unordered collection of data known as set. • It does not contain any duplicate values or elements. • Union, Intersection, Difference and Symmetric Difference  Operations which are performed on sets
  • 38. • Union (|): It performs on two sets returns all the elements from both the sets. • Intersection (&) : It performs on two sets returns all the elements which are common in both the sets • Difference (-): It performs on two sets set1 and set2 returns the elements which are present in set1 but not in set2. • Symmetric Difference (^): It performs on two sets returns the element which are present in either set1 or set2 but not in both.
  • 40. Practice >>>intersection = grp1 & grp2 #intersection >>>intersection >>>union=grp1 | grp2 # Union of grp1 & grp2 >>>union >>>difference=grp1-grp2 >>>sym_diff = grp1 ^ grp2
  • 41. Type() function type() function is a built-in function which returns the datatype of an arbitrary object.
  • 43. INPUT FROM KEYBOARD 1. input() 2. raw_input()
  • 44. Input() function • Input() function interprets the input provided by the user, i.e. if user provides an integer value as input then the input function will return its integer value. • On the other hand, if the user has input a string, the function will return a string
  • 45. Practice >>>name = input(“What is your name?”) >>>print (“Hello”+name) >>>age=int(input(“Enter your age?”)) >>>age >>>hobbies=input(“What are your hobbies?”) >>>hobbies
  • 47. Raw_input() function • It takes the input from the user but it does not interpret the input and also it returns the input of the user without doing any changes, i.e. raw. • Then, we can change this raw input into any data type which is needed for our program.
  • 48. Practice # No casting >>>age=raw_input(“Enter your age?”) >>>type(age) #Using type casting function to convert input to integer >>>age=int(raw_input(“What is your age?”)) >>>type(age)