SlideShare a Scribd company logo
Introduction to Python
Programming
Dr.S.Sangeetha
Department of Computer Applications
National Institute of Technology
Tiruchirappalli
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
History
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Features
Dr.S.Sangeetha, Department of Computer
Applications, NIT Trichy
Working Environment
Anaconda (written in Python)
• Anaconda is a free and open source distribution
• Simplifies package management and deployment
• Package versions are managed by Package Management system Conda
• 1400 + data science packages for Python & R
• IDES – Jupyter, Spyder, Jupyter Lab, R Studio
1. Data Science Libraries in Anaconda
▪ Data Analytics & Scientific Computing – NumPy, SciPy, Pandas , Numba
▪ Visualization
Bokeh, Holoviews, Data shader, Matplotlib
▪ Machine Learning
TensorFlow, H2o, Theano, Scikit learn
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Working Environment Cont…
2. Conda the data science Package & environment Manager
▪ Automatically manage all packages
▪ Work across all platforms (Linux, MacOS, windows)
▪ Create virtual environments
▪ Download Conda Packages from Anaconda, Anaconda enterprise,
conda forge, Anaconda cloud
3. Anaconda Navigator
▪ Desktop Portal
Dr.S.Sangeetha, Department of Computer
Applications, NIT Trichy
Web framework
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Full Stack
Provide complete support
(Form generations, Template Layouts)
Non – Full Stack
Do not provide additional
functionalities
▪ Django
▪ Web2py
▪ Gitto
▪ Pylon
• Bottle
• Cherrypy
• Flask
Python GUI
▪TKinter – Bundled with Python
▪WXPython
▪PYGUI – Light weight, cross Platform
▪PYside – Nokia
▪PyGObject – bindings for GTK+
▪PyQt5 – bindings for QT application framework
▪Kivy – cross-platform UI creation tool
▪Glade
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Why it is Slow?
1) Dynamically typed Language
2) Interpreted code is always slower
Takes more instructions in order to implement actual machine instruction
3) GIL (Global Interpreter Lock)
➢Allows only one thread to hold the control of python Interpreter
➢Bottleneck in CPU bound multi-threaded code [Even in multi thread architecture
with more than CPU core]
➢Prevents CPU bound threads from executing parallel
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
PyPy
1) Uses JIT (Just in Time Compiler)
• JIT (dynamic Translation / run time Compilation)
• Executing computer code that involves compilation during execution of a program
• At run time, prior to execution
• JIT consist of byte code translation to machine code
• JIT compilation combines the speed of compiled code with flexibility of interpretation
• Suited for late bound data types
2) Less memory space
3) Stackless support
• Basic cooperative multitasking.
• Uses ‘tasklets’ to wrap functions
• Creates “micro threads”
• Scheduled to execute concurrently
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Basics of Python
Comments
# Single line or inline comments
1.Data types
Python provides data types such as numeric, complex, strings and Boolean.
It supports no type Declaration.
Numeric
Python has two numeric types int and float
Strings
• ‘Welcome’
• “Welcome”
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Data types cont.….
Multiline strings – Triple quotes
“““Welcome to Python course.
You will learn basics to advanced concepts”””
Boolean
bool is a subtype of int, where True == 1 and False == 0
Complex
>>> complex (10,2)
(10+2j)
>>> x=10+5j
>>> x
(10+5j)
>>> type((10+2j))
<class 'complex'>
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Operators
() {}[] Tuple, List, Dictionary, set display
f (….), x [ :], X.attr Function calls, slicing, Attribute reference
** Exponentiation - Right to left associativity
x, -x Bitwise Not, Negative
*, /, //,% Multiplication, division, floor division,
Modulo division
+ - Additive
<< >> Shift
& Bitwise AND
 Bitwise XOR
| Bitwise OR
in, not in, is, is not <, <=, >, >=, <>, !=, == Membership, Comparison/relational
not Boolean NOT
and Boolean AND
or Boolean OR
lambda Lambda expressions
Quick Demo
Dr.S.Sangeetha, Department of Computer Applications, NIT
Trichy
Objects
• Objects are Python’s abstraction for data.
• Objects are typed
• All data in a Python program is represented by objects or by relations
between objects.
• Every object has an identity, type and value.
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Objects Cont..
Object’s Identity
• Objects have Identity
• Identity is unique and fixed during an object's lifetime
• id() returns an object's identity
• An object’s identity never changes once it has been created
Object Type
• Objects are tagged with their type at runtime
• type determines the operations that the object supports
• type() returns objects type
• Objects contain pointers to their data blob (Binary large object)
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Object categories
▪ Python objects are classified in to categories such as mutable and immutable
• The value of some objects can change.
• Objects whose value can change are mutable
• Objects whose value is unchangeable once they are created are
immutable.
Mutability of the object is determined by its type
• Immutable Object: int, float, complex, string, tuple, bool
• Mutable Object: list, dict, set, byte array, user-defined classes
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Object size
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
(100).__sizeof__ ()
Object Structure
Dr.S.Sangeetha, Department of Computer
Applications, NIT Trichy
Variable
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
All variable names are references to the values or objects.
Automatic Garbage Collection
Reference count
sys.getrefcount(100)
del x
del y
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Addons
• Cascading
x=y=z=1+1+1
• Swap
c=4, d=5
c,d = d,c
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Strings
• No character type in Python
• Both ' and “create string literals
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Slicing
print(X[0:2])
print(X[4:6])
print(X[1:3])
print(X[:3])
print(X[4:])
print(X[1:5:2]) #step size as 3rd parameter
print(X[4::-2])
PY
ON
YT
PYT
ON
YH
OTP
print(X[::-1]) # NOHTYP
Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
Quick Demo
Dr.S.Sangeetha, Department of Computer Applications, NIT
Trichy
Immutability
>>> x="In India"
>>> id(x)
64787744
>>> x=x+' We have'
>>> x
'In India We have'
>>> id(x)
64763184
>>> y="India"
>>> id(y)
64799392
>>> y[2]="o"
TypeError: 'str'
object does not
support item
assignment
Dr.S.Sangeetha, Department of Computer Applications, NIT
Trichy
String Functions
X = "Welcome to India! "
print(X.lower())
print(X.title())
print(X.upper())
print(X.strip())
print(X.strip('W'))
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
welcome to india!
Welcome To India!
WELCOME TO INDIA!
Welcome to India!
elcome to India!
String Functions
X = "Welcome to India!"
print(X.startswith('We'))
print(X.endswith('ia!'))
print(X.isalpha()) # => False (due to '!’)
True
True
False
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Functions
X = "Welcome to India! "
#search
print('in is found in position',X.find('in’))
#-1 if not found
in is found in position -1
print('In is found in position', X.find('In’))
In is found in position 11
#Replace
print(X.replace('ia', 'onesia'))
Welcome to Indonesia!
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Formatting
# Curly braces are placeholders
print ('{} is a capital of {}'.format('New Delhi', 'India'))
New Delhi is a capital of India
# position in placeholders
print ("{0} is a capital of {1} in the continent {2}
".format('New Delhi', 'India', 'Asia'))
New Delhi is a capital of India in the continent Asia
# Key of the data items in the placeholders
print("{name} loves {food}". format(name="Reena",
food="Pizza"))
Reena loves Pizza
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Formatting
# index in the placeholders
Fruits = ['Apple', 'Orange’, 'Guava']
print("{f[0]} is good compared to {f[1]}".format(f=Fruits))
Apple is good compared to Orange
# Evaluated expressions to strings
print ("Square of {} is {}".format (8, 8 ** 2))
Square of 8 is 64
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Functions
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Functions
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Functions
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
String Functions
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Other Formatting
print("{:5.2f}".format(3.14159))
3.14
# Reserve spaces and print in middle
print('{:^10}'.format('Centre'))
Centre
# Reserve spaces and print it Left
print('{:<10}'.format('Left'))
Left
# Reserve spaces and print string right
print('{:>10}'.format('Right'))
Right Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Other Formatting
# Padding character
print('{:*^10}'.format('Centre'))
**Centre**
print('{:*<10}'.format('Left'))
Left******
print('{:*>10}'.format('Right'))
*****Right
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Reading Input and Printing output
str=input ("Enter any value")
print (‘output: ', str)
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Writing Simple Program
Demo
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Reference Book
Guido van Rossum and Fred L. Drake Jr, “An Introduction to Python “
Revised and updated for Python 3.2, Network Theory Ltd., 2011.
Dr.S.Sangeetha, Department of Computer Applications,
NIT Trichy
Ad

More Related Content

What's hot (20)

Data structure
Data structureData structure
Data structure
Muhammad Farhan
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Rahul Jain
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
Vrushali Dhanokar
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
Sumathi MathanMohan
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
Akhil Kaushik
 
5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tuple5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tuple
SanjayKumarMahto1
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structure
eShikshak
 
Machine Learning - Supervised learning
Machine Learning - Supervised learningMachine Learning - Supervised learning
Machine Learning - Supervised learning
Maneesha Caldera
 
Introduction of Machine learning and Deep Learning
Introduction of Machine learning and Deep LearningIntroduction of Machine learning and Deep Learning
Introduction of Machine learning and Deep Learning
Madhu Sanjeevi (Mady)
 
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMINGCOMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
Infinity Tech Solutions
 
Machine learning libraries with python
Machine learning libraries with pythonMachine learning libraries with python
Machine learning libraries with python
VishalBisht9217
 
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET Journal
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
ijceronline
 
Introduction to-machine-learning
Introduction to-machine-learningIntroduction to-machine-learning
Introduction to-machine-learning
Babu Priyavrat
 
Python libraries
Python librariesPython libraries
Python libraries
Venkat Projects
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
iqbalphy1
 
Data Structures 2004
Data Structures 2004Data Structures 2004
Data Structures 2004
Sanjay Goel
 
Neural Networks with Google TensorFlow
Neural Networks with Google TensorFlowNeural Networks with Google TensorFlow
Neural Networks with Google TensorFlow
Darshan Patel
 
1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func
SanjayKumarMahto1
 
Data structures
Data structuresData structures
Data structures
Saurabh Mishra
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Rahul Jain
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
Vrushali Dhanokar
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
Akhil Kaushik
 
5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tuple5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tuple
SanjayKumarMahto1
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structure
eShikshak
 
Machine Learning - Supervised learning
Machine Learning - Supervised learningMachine Learning - Supervised learning
Machine Learning - Supervised learning
Maneesha Caldera
 
Introduction of Machine learning and Deep Learning
Introduction of Machine learning and Deep LearningIntroduction of Machine learning and Deep Learning
Introduction of Machine learning and Deep Learning
Madhu Sanjeevi (Mady)
 
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMINGCOMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
Infinity Tech Solutions
 
Machine learning libraries with python
Machine learning libraries with pythonMachine learning libraries with python
Machine learning libraries with python
VishalBisht9217
 
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET Journal
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
ijceronline
 
Introduction to-machine-learning
Introduction to-machine-learningIntroduction to-machine-learning
Introduction to-machine-learning
Babu Priyavrat
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
iqbalphy1
 
Data Structures 2004
Data Structures 2004Data Structures 2004
Data Structures 2004
Sanjay Goel
 
Neural Networks with Google TensorFlow
Neural Networks with Google TensorFlowNeural Networks with Google TensorFlow
Neural Networks with Google TensorFlow
Darshan Patel
 
1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func
SanjayKumarMahto1
 

Similar to Introduction to Python Objects and Strings (20)

2015 03-28-eb-final
2015 03-28-eb-final2015 03-28-eb-final
2015 03-28-eb-final
Christopher Wilson
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with PythonData Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
Data analysis using python in Jupyter notebook.pptx
Data analysis using python  in Jupyter notebook.pptxData analysis using python  in Jupyter notebook.pptx
Data analysis using python in Jupyter notebook.pptx
ssuserc26f8f
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
Sasha Goldshtein
 
Analysis Mechanical system using Artificial intelligence
Analysis Mechanical system using Artificial intelligenceAnalysis Mechanical system using Artificial intelligence
Analysis Mechanical system using Artificial intelligence
anishahmadgrd222
 
Python programming
Python programmingPython programming
Python programming
saroja20
 
Lacture 1- Programming using python.pptx
Lacture 1- Programming using python.pptxLacture 1- Programming using python.pptx
Lacture 1- Programming using python.pptx
hello236603
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
UpasnaSharma37
 
Toolboxes for data scientists
Toolboxes for data scientistsToolboxes for data scientists
Toolboxes for data scientists
Sudipto Krishna Dutta
 
Python for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive GuidePython for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive Guide
priyanka rajput
 
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jh
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jhInternship (7)gfytfyugiujhoiipobjhvyuhjkb jh
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jh
sidd233245456df
 
Internship (7)szgsdgszdssagsagzsvszszvsvszfvsz
Internship (7)szgsdgszdssagsagzsvszszvsvszfvszInternship (7)szgsdgszdssagsagzsvszszvsvszfvsz
Internship (7)szgsdgszdssagsagzsvszszvsvszfvsz
sidd233245456df
 
Python
PythonPython
Python
Rural Engineering College Hulkoti
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
Jen Yee Hong
 
Python: The Dynamic!
Python: The Dynamic!Python: The Dynamic!
Python: The Dynamic!
Omid Mogharian
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Standard Libraries in Python Programming
Standard Libraries in Python ProgrammingStandard Libraries in Python Programming
Standard Libraries in Python Programming
Rohan Chougule
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
SajjadAbdullah4
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
CP-Union
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with PythonData Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
Data analysis using python in Jupyter notebook.pptx
Data analysis using python  in Jupyter notebook.pptxData analysis using python  in Jupyter notebook.pptx
Data analysis using python in Jupyter notebook.pptx
ssuserc26f8f
 
Analysis Mechanical system using Artificial intelligence
Analysis Mechanical system using Artificial intelligenceAnalysis Mechanical system using Artificial intelligence
Analysis Mechanical system using Artificial intelligence
anishahmadgrd222
 
Python programming
Python programmingPython programming
Python programming
saroja20
 
Lacture 1- Programming using python.pptx
Lacture 1- Programming using python.pptxLacture 1- Programming using python.pptx
Lacture 1- Programming using python.pptx
hello236603
 
Python for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive GuidePython for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive Guide
priyanka rajput
 
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jh
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jhInternship (7)gfytfyugiujhoiipobjhvyuhjkb jh
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jh
sidd233245456df
 
Internship (7)szgsdgszdssagsagzsvszszvsvszfvsz
Internship (7)szgsdgszdssagsagzsvszszvsvszfvszInternship (7)szgsdgszdssagsagzsvszszvsvszfvsz
Internship (7)szgsdgszdssagsagzsvszszvsvszfvsz
sidd233245456df
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
Jen Yee Hong
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Standard Libraries in Python Programming
Standard Libraries in Python ProgrammingStandard Libraries in Python Programming
Standard Libraries in Python Programming
Rohan Chougule
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
CP-Union
 
Ad

More from Sangeetha S (6)

Flowchart
FlowchartFlowchart
Flowchart
Sangeetha S
 
Introduction to Computers - Hardware
Introduction to Computers - HardwareIntroduction to Computers - Hardware
Introduction to Computers - Hardware
Sangeetha S
 
Regression models
Regression  modelsRegression  models
Regression models
Sangeetha S
 
R Probability and Statistics
R Probability and StatisticsR Probability and Statistics
R Probability and Statistics
Sangeetha S
 
R Introduction
R IntroductionR Introduction
R Introduction
Sangeetha S
 
Quiz creation and Launching using Socrative
Quiz creation and Launching using SocrativeQuiz creation and Launching using Socrative
Quiz creation and Launching using Socrative
Sangeetha S
 
Introduction to Computers - Hardware
Introduction to Computers - HardwareIntroduction to Computers - Hardware
Introduction to Computers - Hardware
Sangeetha S
 
Regression models
Regression  modelsRegression  models
Regression models
Sangeetha S
 
R Probability and Statistics
R Probability and StatisticsR Probability and Statistics
R Probability and Statistics
Sangeetha S
 
Quiz creation and Launching using Socrative
Quiz creation and Launching using SocrativeQuiz creation and Launching using Socrative
Quiz creation and Launching using Socrative
Sangeetha S
 
Ad

Recently uploaded (20)

Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 

Introduction to Python Objects and Strings

  • 1. Introduction to Python Programming Dr.S.Sangeetha Department of Computer Applications National Institute of Technology Tiruchirappalli
  • 2. Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 3. History Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 4. Features Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 5. Working Environment Anaconda (written in Python) • Anaconda is a free and open source distribution • Simplifies package management and deployment • Package versions are managed by Package Management system Conda • 1400 + data science packages for Python & R • IDES – Jupyter, Spyder, Jupyter Lab, R Studio 1. Data Science Libraries in Anaconda ▪ Data Analytics & Scientific Computing – NumPy, SciPy, Pandas , Numba ▪ Visualization Bokeh, Holoviews, Data shader, Matplotlib ▪ Machine Learning TensorFlow, H2o, Theano, Scikit learn Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 6. Working Environment Cont… 2. Conda the data science Package & environment Manager ▪ Automatically manage all packages ▪ Work across all platforms (Linux, MacOS, windows) ▪ Create virtual environments ▪ Download Conda Packages from Anaconda, Anaconda enterprise, conda forge, Anaconda cloud 3. Anaconda Navigator ▪ Desktop Portal Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 7. Web framework Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy Full Stack Provide complete support (Form generations, Template Layouts) Non – Full Stack Do not provide additional functionalities ▪ Django ▪ Web2py ▪ Gitto ▪ Pylon • Bottle • Cherrypy • Flask
  • 8. Python GUI ▪TKinter – Bundled with Python ▪WXPython ▪PYGUI – Light weight, cross Platform ▪PYside – Nokia ▪PyGObject – bindings for GTK+ ▪PyQt5 – bindings for QT application framework ▪Kivy – cross-platform UI creation tool ▪Glade Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 9. Why it is Slow? 1) Dynamically typed Language 2) Interpreted code is always slower Takes more instructions in order to implement actual machine instruction 3) GIL (Global Interpreter Lock) ➢Allows only one thread to hold the control of python Interpreter ➢Bottleneck in CPU bound multi-threaded code [Even in multi thread architecture with more than CPU core] ➢Prevents CPU bound threads from executing parallel Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 10. PyPy 1) Uses JIT (Just in Time Compiler) • JIT (dynamic Translation / run time Compilation) • Executing computer code that involves compilation during execution of a program • At run time, prior to execution • JIT consist of byte code translation to machine code • JIT compilation combines the speed of compiled code with flexibility of interpretation • Suited for late bound data types 2) Less memory space 3) Stackless support • Basic cooperative multitasking. • Uses ‘tasklets’ to wrap functions • Creates “micro threads” • Scheduled to execute concurrently Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 11. Basics of Python Comments # Single line or inline comments 1.Data types Python provides data types such as numeric, complex, strings and Boolean. It supports no type Declaration. Numeric Python has two numeric types int and float Strings • ‘Welcome’ • “Welcome” Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 12. Data types cont.…. Multiline strings – Triple quotes “““Welcome to Python course. You will learn basics to advanced concepts””” Boolean bool is a subtype of int, where True == 1 and False == 0 Complex >>> complex (10,2) (10+2j) >>> x=10+5j >>> x (10+5j) >>> type((10+2j)) <class 'complex'> Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 13. Operators () {}[] Tuple, List, Dictionary, set display f (….), x [ :], X.attr Function calls, slicing, Attribute reference ** Exponentiation - Right to left associativity x, -x Bitwise Not, Negative *, /, //,% Multiplication, division, floor division, Modulo division + - Additive << >> Shift & Bitwise AND  Bitwise XOR | Bitwise OR in, not in, is, is not <, <=, >, >=, <>, !=, == Membership, Comparison/relational not Boolean NOT and Boolean AND or Boolean OR lambda Lambda expressions
  • 14. Quick Demo Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 15. Objects • Objects are Python’s abstraction for data. • Objects are typed • All data in a Python program is represented by objects or by relations between objects. • Every object has an identity, type and value. Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 16. Objects Cont.. Object’s Identity • Objects have Identity • Identity is unique and fixed during an object's lifetime • id() returns an object's identity • An object’s identity never changes once it has been created Object Type • Objects are tagged with their type at runtime • type determines the operations that the object supports • type() returns objects type • Objects contain pointers to their data blob (Binary large object) Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 17. Object categories ▪ Python objects are classified in to categories such as mutable and immutable • The value of some objects can change. • Objects whose value can change are mutable • Objects whose value is unchangeable once they are created are immutable. Mutability of the object is determined by its type • Immutable Object: int, float, complex, string, tuple, bool • Mutable Object: list, dict, set, byte array, user-defined classes Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 18. Object size Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy (100).__sizeof__ ()
  • 19. Object Structure Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 20. Variable Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy All variable names are references to the values or objects.
  • 21. Automatic Garbage Collection Reference count sys.getrefcount(100) del x del y Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 22. Addons • Cascading x=y=z=1+1+1 • Swap c=4, d=5 c,d = d,c Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 23. Strings • No character type in Python • Both ' and “create string literals Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 24. String Slicing print(X[0:2]) print(X[4:6]) print(X[1:3]) print(X[:3]) print(X[4:]) print(X[1:5:2]) #step size as 3rd parameter print(X[4::-2]) PY ON YT PYT ON YH OTP print(X[::-1]) # NOHTYP Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 25. Quick Demo Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 26. Immutability >>> x="In India" >>> id(x) 64787744 >>> x=x+' We have' >>> x 'In India We have' >>> id(x) 64763184 >>> y="India" >>> id(y) 64799392 >>> y[2]="o" TypeError: 'str' object does not support item assignment Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 27. String Functions X = "Welcome to India! " print(X.lower()) print(X.title()) print(X.upper()) print(X.strip()) print(X.strip('W')) Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy welcome to india! Welcome To India! WELCOME TO INDIA! Welcome to India! elcome to India!
  • 28. String Functions X = "Welcome to India!" print(X.startswith('We')) print(X.endswith('ia!')) print(X.isalpha()) # => False (due to '!’) True True False Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 29. String Functions X = "Welcome to India! " #search print('in is found in position',X.find('in’)) #-1 if not found in is found in position -1 print('In is found in position', X.find('In’)) In is found in position 11 #Replace print(X.replace('ia', 'onesia')) Welcome to Indonesia! Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 30. String Formatting # Curly braces are placeholders print ('{} is a capital of {}'.format('New Delhi', 'India')) New Delhi is a capital of India # position in placeholders print ("{0} is a capital of {1} in the continent {2} ".format('New Delhi', 'India', 'Asia')) New Delhi is a capital of India in the continent Asia # Key of the data items in the placeholders print("{name} loves {food}". format(name="Reena", food="Pizza")) Reena loves Pizza Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 31. String Formatting # index in the placeholders Fruits = ['Apple', 'Orange’, 'Guava'] print("{f[0]} is good compared to {f[1]}".format(f=Fruits)) Apple is good compared to Orange # Evaluated expressions to strings print ("Square of {} is {}".format (8, 8 ** 2)) Square of 8 is 64 Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 32. String Functions Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 33. String Functions Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 34. String Functions Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 35. String Functions Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 36. Other Formatting print("{:5.2f}".format(3.14159)) 3.14 # Reserve spaces and print in middle print('{:^10}'.format('Centre')) Centre # Reserve spaces and print it Left print('{:<10}'.format('Left')) Left # Reserve spaces and print string right print('{:>10}'.format('Right')) Right Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 37. Other Formatting # Padding character print('{:*^10}'.format('Centre')) **Centre** print('{:*<10}'.format('Left')) Left****** print('{:*>10}'.format('Right')) *****Right Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 38. Reading Input and Printing output str=input ("Enter any value") print (‘output: ', str) Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 39. Writing Simple Program Demo Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  • 40. Reference Book Guido van Rossum and Fred L. Drake Jr, “An Introduction to Python “ Revised and updated for Python 3.2, Network Theory Ltd., 2011. Dr.S.Sangeetha, Department of Computer Applications, NIT Trichy
  翻译: