SlideShare a Scribd company logo
Python Array
What Is Array?
• An array is an mutable object which store a collection of values of
same data type under a single reference.
• An array store only homogeneous data type.
• Python's array is dynamic array.
• In Python we need declaration of array before use it in program.
• 'array' module must be imported for handling array in Python.
Advantages Of Array
I. Performance: For huge number of elements array take less memory
spaces and execution time also faster if compare with list.
II. Dynamic: Array's size is not fixed, so we can increase or decrease its
size at run time.
III. array module: Python provide 'array' module which contain
different methods, classes, objects to process array very easily.
Array vs. List
Topic Array List
Type of data structure
It is not built - in. We need
import 'array' module
before using array.
It is built - in. There are no
need to import any extra
module or package.
Necessity of declaration
Requires specific function
to declare an array.
No requirement of specific
function to declare a list.
Data type
Support only
homogeneous type.
Always support different
types of data in a list.
Array vs. List
Topic Array List
Handling large data
Store data very compact
way, so array more
efficient to handle large
data.
It is not so much efficient
to handle large data.
Numerical operations
Arryas are efficient for
various types of numerical
operations.
Lists can not handle
numerical operations
directly.
'array' Module
• If you working with array you need to import 'array' module.
• According to Python documentation “This module defines an object
type which can compactly represent an array of basic values:
characters, integers, floating point numbers.”
• Import array module as following way:
>>> import array
Declaring Array
• The syntax of array declaration is:
• 'array_name' is an identifier, which store reference of array object.
• 'array.array( )' first array represent 'array' module and second array
represent array class which resides in 'array' module.
• 'type_code' represent the data type of array's elements.
• '[ elements ]' represent list of values which we want to store in array.
array_name = array.array( type_code, [ elements ] )
List Of 'type_code'
type_code Data type Minimum size in
bytes
'b' Signed integer 1
'B' Unsigned integer 1
'i' Signed integer 2
'I' Unsigned integer 2
'l' Signed integer 4
'L' Unsigned integer 4
List Of 'type_code'
type_code Data type Minimum size in
bytes
'f' Floating point 4
'd' Double precision
floating point
8
'u' Unicode character 2
Array Declaration Example
>>> import array
>>> my_array = array.array( 'i', [ 5, 7, 11, 14 ] )
>>> for i in my_array:
print( i )
5
7
11
14
Programming Example
• A program to create an array to store the characters of word
'Welcome' and display all characters.
>>> import array
>>> my_array = array.array( 'u', [ 'W', 'e', 'l', 'c', 'o', 'm', 'e' ] )
>>> for i in my_array:
print( i )
W m
e e
l
c
o
Different Ways Of Importing Array Module
• Import array module with an alias or alternate name as below:
• Here 'arr' is an alias name of imported module.
• For example:
>>> import array as arr
>>> my_array = arr.array( 'i', [ 5, 7, 11, 14 ] )
>>> import array as arr
Different Ways Of Importing Array Module
• Second way of importing 'array' module is below:
• Here '*' means all. That means we import all things such as classes,
objects, variables etc. of array module in our program.
• For example:
>>> from array import *
>>> my_array = array( 'i', [ 5, 7, 11, 14 ] )
>>> from array import *
Indexing On Arrays
• An index represent position value of an element in an array.
• Array index always start from 0.
• For example:
>>> from array import *
>>> x = array( 'i', [ 5, 7, 11, 14 ] )
>>> print( x[ 2 ] )
11
5 7 11 14
x[ 0 ] x[ 1 ] x[ 2 ] x[ 3 ]
Accessing Array Using Index
- By for loop
from array import *
a = array( 'i', [ 34, 56,-12, 44 ] )
n = len( a )
for i in range( n ):
print( a[ i ], 't', end = ' ' )
34 56 -12 44
Accessing Array Using Index
- By while loop
from array import *
a = array( 'i', [ 34, 56,-12, 44 ] )
n = len( a )
i = 0
while i < n:
print( a[ i ], 't', end = ' ' )
i += 1
34 56 -12 44
Slicing On Array
• By slicing operation we can retrive a piece of array out of an array.
• The syntax of slicing is:
• For example:
array_name[ start: stop: stride ]
>>> x = array( 'i', [ 10, 20, 30, 40, 50, 60, 70, 80, 90 ] )
>>> print( x[ 1: 4 ] )
array('i', [20, 30, 40])
>>> print( x[ 1: : 2 ] )
array('i', [20, 40, 60, 80])
Slicing On Array
array('i', [20, 40, 60, 80])
>>> print( x[ : 8: 2 ] )
array('i', [10, 30, 50, 70])
>>> print( x[ -1: : ] )
array('i', [90])
>>> print( x[ : : -1 ] )
array('i', [90, 80, 70, 60, 50, 40, 30, 20, 10])
>>> print( x[ : -5: -1 ] )
array('i', [90, 80, 70, 60])
>>> print( x[ -5: : ] )
array('i', [50, 60, 70, 80, 90])
Programming Example
• A program to calculate sum of a range of elements in an array.
from array import *
x = array( 'i', [ 10, 20, 30, 40, 50, 60, 70, 80, 90 ] )
sum = 0
for i in x[ 2: 5 ]:
sum = sum + i
print( sum )

More Related Content

What's hot

Arrays in python
Arrays in pythonArrays in python
Arrays in python
Lifna C.S
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
Srinivas Narasegouda
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Queue
QueueQueue
Tuple in python
Tuple in pythonTuple in python
Tuple in python
vikram mahendra
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
Lists
ListsLists
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
Sharath Ankrajegowda
 
NumPy
NumPyNumPy
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
Emertxe Information Technologies Pvt Ltd
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
Imdadul Himu
 
Data types in python
Data types in pythonData types in python
Data types in python
Learnbay Datascience
 

What's hot (20)

Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Python list
Python listPython list
Python list
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Queue
QueueQueue
Queue
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 
Lists
ListsLists
Lists
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
NumPy
NumPyNumPy
NumPy
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Data types in python
Data types in pythonData types in python
Data types in python
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
Data types in python
Data types in pythonData types in python
Data types in python
 

Similar to Python array

Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
Array
ArrayArray
Array
PRN USM
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
JayanthiM19
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
MamataAnilgod
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Kashif Nawab
 
ARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptxARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptx
DarellMuchoko
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
2 Arrays & Strings.pptx
2 Arrays & Strings.pptx2 Arrays & Strings.pptx
2 Arrays & Strings.pptx
aarockiaabinsAPIICSE
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
DrRShaliniVISTAS
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
ShahinAhmed49
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
HimanshuKansal22
 
Arrays
ArraysArrays
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#
Umar Farooq
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
valerie5142000
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
ansariparveen06
 
array Details
array Detailsarray Details
array Details
shivas379526
 

Similar to Python array (20)

Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Array
ArrayArray
Array
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
ARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptxARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptx
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
2 Arrays & Strings.pptx
2 Arrays & Strings.pptx2 Arrays & Strings.pptx
2 Arrays & Strings.pptx
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Arrays
ArraysArrays
Arrays
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
array Details
array Detailsarray Details
array Details
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 

Python array

  • 2. What Is Array? • An array is an mutable object which store a collection of values of same data type under a single reference. • An array store only homogeneous data type. • Python's array is dynamic array. • In Python we need declaration of array before use it in program. • 'array' module must be imported for handling array in Python.
  • 3. Advantages Of Array I. Performance: For huge number of elements array take less memory spaces and execution time also faster if compare with list. II. Dynamic: Array's size is not fixed, so we can increase or decrease its size at run time. III. array module: Python provide 'array' module which contain different methods, classes, objects to process array very easily.
  • 4. Array vs. List Topic Array List Type of data structure It is not built - in. We need import 'array' module before using array. It is built - in. There are no need to import any extra module or package. Necessity of declaration Requires specific function to declare an array. No requirement of specific function to declare a list. Data type Support only homogeneous type. Always support different types of data in a list.
  • 5. Array vs. List Topic Array List Handling large data Store data very compact way, so array more efficient to handle large data. It is not so much efficient to handle large data. Numerical operations Arryas are efficient for various types of numerical operations. Lists can not handle numerical operations directly.
  • 6. 'array' Module • If you working with array you need to import 'array' module. • According to Python documentation “This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers.” • Import array module as following way: >>> import array
  • 7. Declaring Array • The syntax of array declaration is: • 'array_name' is an identifier, which store reference of array object. • 'array.array( )' first array represent 'array' module and second array represent array class which resides in 'array' module. • 'type_code' represent the data type of array's elements. • '[ elements ]' represent list of values which we want to store in array. array_name = array.array( type_code, [ elements ] )
  • 8. List Of 'type_code' type_code Data type Minimum size in bytes 'b' Signed integer 1 'B' Unsigned integer 1 'i' Signed integer 2 'I' Unsigned integer 2 'l' Signed integer 4 'L' Unsigned integer 4
  • 9. List Of 'type_code' type_code Data type Minimum size in bytes 'f' Floating point 4 'd' Double precision floating point 8 'u' Unicode character 2
  • 10. Array Declaration Example >>> import array >>> my_array = array.array( 'i', [ 5, 7, 11, 14 ] ) >>> for i in my_array: print( i ) 5 7 11 14
  • 11. Programming Example • A program to create an array to store the characters of word 'Welcome' and display all characters. >>> import array >>> my_array = array.array( 'u', [ 'W', 'e', 'l', 'c', 'o', 'm', 'e' ] ) >>> for i in my_array: print( i ) W m e e l c o
  • 12. Different Ways Of Importing Array Module • Import array module with an alias or alternate name as below: • Here 'arr' is an alias name of imported module. • For example: >>> import array as arr >>> my_array = arr.array( 'i', [ 5, 7, 11, 14 ] ) >>> import array as arr
  • 13. Different Ways Of Importing Array Module • Second way of importing 'array' module is below: • Here '*' means all. That means we import all things such as classes, objects, variables etc. of array module in our program. • For example: >>> from array import * >>> my_array = array( 'i', [ 5, 7, 11, 14 ] ) >>> from array import *
  • 14. Indexing On Arrays • An index represent position value of an element in an array. • Array index always start from 0. • For example: >>> from array import * >>> x = array( 'i', [ 5, 7, 11, 14 ] ) >>> print( x[ 2 ] ) 11 5 7 11 14 x[ 0 ] x[ 1 ] x[ 2 ] x[ 3 ]
  • 15. Accessing Array Using Index - By for loop from array import * a = array( 'i', [ 34, 56,-12, 44 ] ) n = len( a ) for i in range( n ): print( a[ i ], 't', end = ' ' ) 34 56 -12 44
  • 16. Accessing Array Using Index - By while loop from array import * a = array( 'i', [ 34, 56,-12, 44 ] ) n = len( a ) i = 0 while i < n: print( a[ i ], 't', end = ' ' ) i += 1 34 56 -12 44
  • 17. Slicing On Array • By slicing operation we can retrive a piece of array out of an array. • The syntax of slicing is: • For example: array_name[ start: stop: stride ] >>> x = array( 'i', [ 10, 20, 30, 40, 50, 60, 70, 80, 90 ] ) >>> print( x[ 1: 4 ] ) array('i', [20, 30, 40]) >>> print( x[ 1: : 2 ] ) array('i', [20, 40, 60, 80])
  • 18. Slicing On Array array('i', [20, 40, 60, 80]) >>> print( x[ : 8: 2 ] ) array('i', [10, 30, 50, 70]) >>> print( x[ -1: : ] ) array('i', [90]) >>> print( x[ : : -1 ] ) array('i', [90, 80, 70, 60, 50, 40, 30, 20, 10]) >>> print( x[ : -5: -1 ] ) array('i', [90, 80, 70, 60]) >>> print( x[ -5: : ] ) array('i', [50, 60, 70, 80, 90])
  • 19. Programming Example • A program to calculate sum of a range of elements in an array. from array import * x = array( 'i', [ 10, 20, 30, 40, 50, 60, 70, 80, 90 ] ) sum = 0 for i in x[ 2: 5 ]: sum = sum + i print( sum )