SlideShare a Scribd company logo
PYTHON
LANGUAGE
Dr. B. Subashini,
Assistant Professor of Computer Applications,
V.V.Vanniaperumal College for Women,
Virudhunagar
BRIEF HISTORY OF PYTHON
• Invented in the Netherlands, early 90s by
Guido van Rossum
• Named after Monty Python
• Open sourced from the beginning
• Considered a scripting language, but is much
more
• Scalable, object oriented and functional from
the beginning
• Used by Google from the beginning
• Increasingly popular
PYTHON
• Python can be used on a server to create web
applications.
• Python can be used alongside software to create
workflows.
• Python can connect to database systems. It can also read
and modify files.
• Python can be used to handle big data
and perform complex mathematics.
• Python can be used for rapid prototyping,
or for production-ready software development.
WHY PYTHON?
• Python works on different platforms (Windows, Mac,
Linux, Raspberry Pi, etc).
• Python has a simple syntax similar to the English
language.
• Python has syntax that allows developers to write
programs with fewer lines than some other programming
languages.
• Python runs on an interpreter system, meaning that
code can be executed as soon as it is written. This
means that prototyping can be very quick.
• Python can be treated in a procedural way,
an object-oriented way or a functional way.
VERSION
• The most recent major version of Python is
Python 3
• 3.12.0 is the latest version of Python released on
October 2, 2023
• However, Python 2 being updated with security,
is still quite popular
PYTHON SYNTAX
• Python was designed for readability, and has some
similarities to the English language with influence
from mathematics.
• Python uses new lines to complete a command, as
opposed to other programming languages which
often use semicolons or parentheses.
• Python relies on indentation, using whitespace, to
define scope; such as the scope of loops, functions
and classes. Other programming languages often
use curly-brackets for this purpose.
COMMENTS
• Comments can be used to explain Python code.
• Comments can be used to make the code more
readable.
• Comments can be used to prevent execution when
testing code.
• Example:
• #This is a comment
print("Hello, World!")
VARIABLES
• Variables are containers for storing data values.
• Python has no command for declaring a variable.
• A variable is created the moment just first assign a value
to it.
• x = 5
y = "John"
print(x)
print(y)
VARIABLE NAMES
• A variable name must start with a letter or the
underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and
AGE are three different variables)
• A variable name cannot be any of the Python
Keywords.
BUILT IN DATA TYPES
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
NUMPY
• Stands for Numerical Python
• Is the fundamental package required for high performance
computing and data analysis
• NumPy is so important for numerical computations in
Python is because it is designed for efficiency on large
arrays of data.
• It provides ndarray for creating multiple dimensional arrays.
• Internally stores data in a contiguous block of
memory, independent of other built-in
Python objects, use much less memory
than built-in Python sequences.
NUMPY NDARRAY VS LIST
• Standard math functions for fast operations on entire arrays of data
without having to write loops
• NumPy Arrays are important because they enable to express batch
operations on data without writing any for loops. We call this
vectorization.
• One of the key features of NumPy is its N-dimensional array object, or
ndarray, which is a fast, flexible container for large datasets in Python.
• Whenever you see “array,” “NumPy array,” or “ndarray” in the text, with
few exceptions they all refer to the same thing: the ndarray object.
• NumPy-based algorithms are generally 10 to
100 times faster (or more) than their pure Python
counterparts and use significantly less memory.
import numpy as np
my_arr = np.arange(1000000)
NDARRAY
• ndarray is used for storage of homogeneous data
• i.e., all elements the same type
• Every array must have a shape and a dtype
• Supports convenient slicing, indexing and efficient
vectorized computation
import numpy as np
data1 = [6, 7, 5, 8, 0, 1]
arr1 = np.array(data1)
print(arr1)
CREATING NDARRAYS
Using list of lists
import numpy as np
data2 = [[1, 2, 3, 4], [5, 6, 7, 8]] #list of lists
arr2 = np.array(data2)
print(arr2.ndim) #2
print(arr2.shape) # (2,4)
array = np.array([[0,1,2],[2,3,4]])
[[0 1 2]
[2 3 4]]
array = np.zeros((2,3))
[[0. 0. 0.]
[0. 0. 0.]]
array = np.ones((2,3))
[[1. 1. 1.]
[1. 1. 1.]]
array = np.arange(0, 10, 2)
[0, 2, 4, 6, 8]
array = np.eye(3)
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
array = np.random.randint(0,
10, (3,3))
[[6 4 3]
[1 5 6]
[9 8 5]]
CREATING NDARRAYS
ARITHMETIC WITH NUMPY
ARRAYS
• Any arithmetic operations between equal-size arrays
applies the operation element-wise:
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
[[1 2 3]
[4 5 6]]
print(arr * arr)
[[ 1 4 9]
[16 25 36]]
print(arr - arr)
[[0 0 0]
[0 0 0]]
ARITHMETIC WITH NUMPY
ARRAYS
• Arithmetic operations with scalars propagate the scalar
argument to each element in the array:
arr = np.array([[1., 2., 3.], [4., 5., 6.]])
print(arr)
[[1. 2. 3.]
[4. 5. 6.]]
print(arr **2)
[[ 1. 4. 9.]
[16. 25. 36.]]
ARITHMETIC WITH NUMPY
ARRAYS
• Comparisons between arrays of the same size yield
boolean arrays:
arr = np.array([[1., 2., 3.], [4., 5., 6.]])
print(arr)
[[1. 2. 3.]
[4. 5. 6.]]
arr2 = np.array([[0., 4., 1.], [7., 2., 12.]])
print(arr2)
[[ 0. 4. 1.]
[ 7. 2. 12.]]
print(arr2 > arr)
[[False True False]
[ True False True]]
INDEXING AND SLICING
• One-dimensional arrays are simple; on the surface they act
similarly to Python lists:
arr = np.arange(10)
print(arr) # [0 1 2 3 4 5 6 7 8 9]
print(arr[5]) #5
print(arr[5:8]) #[5 6 7]
arr[5:8] = 12
print(arr) #[ 0 1 2 3 4 12 12 12 8 9]
INDEXING AND SLICING
• An important first distinction from Python’s built-in lists is
that array slices are views on the original array.
• This means that the data is not copied, and any modifications to
the view will be reflected in the source array.
arr = np.arange(10)
print(arr) # [0 1 2 3 4 5 6 7 8 9]
arr_slice = arr[5:8]
print(arr_slice) # [5 6 7]
arr_slice[1] = 12345
print(arr)
# [ 0 1 2 3 4 5 12345 7 8 9]
arr_slice[:] = 64
print(arr)
# [ 0 1 2 3 4 64 64 64 8 9]
INDEXING
• In a two-dimensional array, the elements at each index are
no longer scalars but rather one-dimensional arrays:
• Thus, individual elements can be accessed recursively.
But that is a bit too much work, so we can
pass a comma-separated list of indices
to select individual elements.
• So these are equivalent:
arr2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(arr2d[2]) # [7 8 9]
print(arr2d[0][2]) # 3
print(arr2d[0, 2]) #3

More Related Content

PPTX
Introduction to numpy.pptx
ssuser0e701a
 
PPTX
modul-python-part1.pptx
Yusuf Ayuba
 
PPTX
UNIT 1 .pptx
Prachi Gawande
 
PPTX
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
PPT
Python
Chetan Khanzode
 
PPTX
1. python programming
sreeLekha51
 
PDF
Python Programming
Saravanan T.M
 
PPTX
bhaskars.pptx
NaveenShankar34
 
Introduction to numpy.pptx
ssuser0e701a
 
modul-python-part1.pptx
Yusuf Ayuba
 
UNIT 1 .pptx
Prachi Gawande
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
1. python programming
sreeLekha51
 
Python Programming
Saravanan T.M
 
bhaskars.pptx
NaveenShankar34
 

Similar to Basic Introduction to Python Programming (20)

PDF
Python (3).pdf
samiwaris2
 
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
PPTX
NumPy.pptx
DrJasmineBeulahG
 
PPTX
bhaskars.pptx
Naveen316549
 
PPTX
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
 
PPTX
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
PPTX
intro to python.pptx
UpasnaSharma37
 
PPTX
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
PPTX
PYTHON INTERNSHIP PPT download free.pptx
dhruvn097
 
PDF
software construction and development.pdf
MuhammadBilalAjmal2
 
PPTX
python programming for beginners and advanced
granjith6
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PPTX
Introduction To Programming In R for data analyst
ssuser26ff68
 
PPTX
DATA ANALYSIS AND VISUALISATION using python
ChiragNahata2
 
PPTX
numpy code and examples with attributes.pptx
swathis752031
 
PPTX
Presentation.pptx
AyushmanTiwari11
 
PPTX
Presentation.pptx
AyushmanTiwari11
 
PPTX
Python Programming 1.pptx
Francis Densil Raj
 
PPTX
Shivam PPT.pptx
ShivamDenge
 
PPTX
python_class.pptx
chandankumar943868
 
Python (3).pdf
samiwaris2
 
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
NumPy.pptx
DrJasmineBeulahG
 
bhaskars.pptx
Naveen316549
 
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
 
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
intro to python.pptx
UpasnaSharma37
 
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
PYTHON INTERNSHIP PPT download free.pptx
dhruvn097
 
software construction and development.pdf
MuhammadBilalAjmal2
 
python programming for beginners and advanced
granjith6
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Introduction To Programming In R for data analyst
ssuser26ff68
 
DATA ANALYSIS AND VISUALISATION using python
ChiragNahata2
 
numpy code and examples with attributes.pptx
swathis752031
 
Presentation.pptx
AyushmanTiwari11
 
Presentation.pptx
AyushmanTiwari11
 
Python Programming 1.pptx
Francis Densil Raj
 
Shivam PPT.pptx
ShivamDenge
 
python_class.pptx
chandankumar943868
 
Ad

More from SubashiniRathinavel (11)

PPTX
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
SubashiniRathinavel
 
PPTX
VB.NET Datatypes.pptx
SubashiniRathinavel
 
PPTX
Presentation1.pptx
SubashiniRathinavel
 
PPTX
Wireless lan security(10.8)
SubashiniRathinavel
 
PPTX
Wireless LAN
SubashiniRathinavel
 
PPTX
Android workshop
SubashiniRathinavel
 
PPTX
Cryptography
SubashiniRathinavel
 
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
SubashiniRathinavel
 
VB.NET Datatypes.pptx
SubashiniRathinavel
 
Presentation1.pptx
SubashiniRathinavel
 
Wireless lan security(10.8)
SubashiniRathinavel
 
Wireless LAN
SubashiniRathinavel
 
Android workshop
SubashiniRathinavel
 
Cryptography
SubashiniRathinavel
 
Ad

Recently uploaded (20)

PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
PDF
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 

Basic Introduction to Python Programming

  • 1. PYTHON LANGUAGE Dr. B. Subashini, Assistant Professor of Computer Applications, V.V.Vanniaperumal College for Women, Virudhunagar
  • 2. BRIEF HISTORY OF PYTHON • Invented in the Netherlands, early 90s by Guido van Rossum • Named after Monty Python • Open sourced from the beginning • Considered a scripting language, but is much more • Scalable, object oriented and functional from the beginning • Used by Google from the beginning • Increasingly popular
  • 3. PYTHON • Python can be used on a server to create web applications. • Python can be used alongside software to create workflows. • Python can connect to database systems. It can also read and modify files. • Python can be used to handle big data and perform complex mathematics. • Python can be used for rapid prototyping, or for production-ready software development.
  • 4. WHY PYTHON? • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). • Python has a simple syntax similar to the English language. • Python has syntax that allows developers to write programs with fewer lines than some other programming languages. • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. • Python can be treated in a procedural way, an object-oriented way or a functional way.
  • 5. VERSION • The most recent major version of Python is Python 3 • 3.12.0 is the latest version of Python released on October 2, 2023 • However, Python 2 being updated with security, is still quite popular
  • 6. PYTHON SYNTAX • Python was designed for readability, and has some similarities to the English language with influence from mathematics. • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.
  • 7. COMMENTS • Comments can be used to explain Python code. • Comments can be used to make the code more readable. • Comments can be used to prevent execution when testing code. • Example: • #This is a comment print("Hello, World!")
  • 8. VARIABLES • Variables are containers for storing data values. • Python has no command for declaring a variable. • A variable is created the moment just first assign a value to it. • x = 5 y = "John" print(x) print(y)
  • 9. VARIABLE NAMES • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case-sensitive (age, Age and AGE are three different variables) • A variable name cannot be any of the Python Keywords.
  • 10. BUILT IN DATA TYPES Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview None Type: NoneType
  • 11. NUMPY • Stands for Numerical Python • Is the fundamental package required for high performance computing and data analysis • NumPy is so important for numerical computations in Python is because it is designed for efficiency on large arrays of data. • It provides ndarray for creating multiple dimensional arrays. • Internally stores data in a contiguous block of memory, independent of other built-in Python objects, use much less memory than built-in Python sequences.
  • 12. NUMPY NDARRAY VS LIST • Standard math functions for fast operations on entire arrays of data without having to write loops • NumPy Arrays are important because they enable to express batch operations on data without writing any for loops. We call this vectorization. • One of the key features of NumPy is its N-dimensional array object, or ndarray, which is a fast, flexible container for large datasets in Python. • Whenever you see “array,” “NumPy array,” or “ndarray” in the text, with few exceptions they all refer to the same thing: the ndarray object. • NumPy-based algorithms are generally 10 to 100 times faster (or more) than their pure Python counterparts and use significantly less memory. import numpy as np my_arr = np.arange(1000000)
  • 13. NDARRAY • ndarray is used for storage of homogeneous data • i.e., all elements the same type • Every array must have a shape and a dtype • Supports convenient slicing, indexing and efficient vectorized computation import numpy as np data1 = [6, 7, 5, 8, 0, 1] arr1 = np.array(data1) print(arr1)
  • 14. CREATING NDARRAYS Using list of lists import numpy as np data2 = [[1, 2, 3, 4], [5, 6, 7, 8]] #list of lists arr2 = np.array(data2) print(arr2.ndim) #2 print(arr2.shape) # (2,4)
  • 15. array = np.array([[0,1,2],[2,3,4]]) [[0 1 2] [2 3 4]] array = np.zeros((2,3)) [[0. 0. 0.] [0. 0. 0.]] array = np.ones((2,3)) [[1. 1. 1.] [1. 1. 1.]] array = np.arange(0, 10, 2) [0, 2, 4, 6, 8] array = np.eye(3) [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] array = np.random.randint(0, 10, (3,3)) [[6 4 3] [1 5 6] [9 8 5]] CREATING NDARRAYS
  • 16. ARITHMETIC WITH NUMPY ARRAYS • Any arithmetic operations between equal-size arrays applies the operation element-wise: arr = np.array([[1, 2, 3], [4, 5, 6]]) print(arr) [[1 2 3] [4 5 6]] print(arr * arr) [[ 1 4 9] [16 25 36]] print(arr - arr) [[0 0 0] [0 0 0]]
  • 17. ARITHMETIC WITH NUMPY ARRAYS • Arithmetic operations with scalars propagate the scalar argument to each element in the array: arr = np.array([[1., 2., 3.], [4., 5., 6.]]) print(arr) [[1. 2. 3.] [4. 5. 6.]] print(arr **2) [[ 1. 4. 9.] [16. 25. 36.]]
  • 18. ARITHMETIC WITH NUMPY ARRAYS • Comparisons between arrays of the same size yield boolean arrays: arr = np.array([[1., 2., 3.], [4., 5., 6.]]) print(arr) [[1. 2. 3.] [4. 5. 6.]] arr2 = np.array([[0., 4., 1.], [7., 2., 12.]]) print(arr2) [[ 0. 4. 1.] [ 7. 2. 12.]] print(arr2 > arr) [[False True False] [ True False True]]
  • 19. INDEXING AND SLICING • One-dimensional arrays are simple; on the surface they act similarly to Python lists: arr = np.arange(10) print(arr) # [0 1 2 3 4 5 6 7 8 9] print(arr[5]) #5 print(arr[5:8]) #[5 6 7] arr[5:8] = 12 print(arr) #[ 0 1 2 3 4 12 12 12 8 9]
  • 20. INDEXING AND SLICING • An important first distinction from Python’s built-in lists is that array slices are views on the original array. • This means that the data is not copied, and any modifications to the view will be reflected in the source array. arr = np.arange(10) print(arr) # [0 1 2 3 4 5 6 7 8 9] arr_slice = arr[5:8] print(arr_slice) # [5 6 7] arr_slice[1] = 12345 print(arr) # [ 0 1 2 3 4 5 12345 7 8 9] arr_slice[:] = 64 print(arr) # [ 0 1 2 3 4 64 64 64 8 9]
  • 21. INDEXING • In a two-dimensional array, the elements at each index are no longer scalars but rather one-dimensional arrays: • Thus, individual elements can be accessed recursively. But that is a bit too much work, so we can pass a comma-separated list of indices to select individual elements. • So these are equivalent: arr2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(arr2d[2]) # [7 8 9] print(arr2d[0][2]) # 3 print(arr2d[0, 2]) #3