SlideShare a Scribd company logo
What is an Array?
How to Create an Array in Python?
Is Python List same as an Array?
Basic Array Operations
• Finding the length of an Array
• Addition
• Removal
• Concatenation
• Slicing
• Looping
Accessing Array Elements
www.edureka.co/python
What is an Array?
www.edureka.co/python
What is an Array?
www.edureka.co/python
→ a
a[0] a[1] a[2] a[3…98] a[99]
1 2 3 … 100
Var_Name
Values →
Index →
Basic structure
of an Array:
An array is basically a data structure which can hold more than one value at a
time. It is a collection or ordered series of elements of the same type.
Is Python List same as an Array?
www.edureka.co/python
Is Python List same as an Array?
Python Arrays and lists have the
same way of storing data.
Arrays take only a single data type
elements but lists can have any
type of data.
Therefore, other than a few
operations, the kind of operations
performed on them are different.
www.edureka.co/python
How to create Arrays in Python?
www.edureka.co/python
Arrays in Python can be created after importing the array module.
How to create Arrays in Python?
→ from array import *
USING *
3
→ import array → import array as arr
WITHOUT ALIAS
1 USING ALIAS
2
www.edureka.co/python
Accessing Array Elements www.edureka.co/python
❑ Access elements using index values.
❑ Indexing starts at 0 and not from 1. Hence, the index number is always 1 less than the length
of the array.
❑ Negative index values can be used as well. The point to remember is that negative indexing
starts from the reverse order of traversal i.e from right to left.
www.edureka.co/python
a[2]=3
Example: a[2]=3
Accessing Array Elements
Basic Array Operations www.edureka.co/python
Operations
Removing/ Deleting
elements of an array
Slicing
Looping through an Array
Basic Array Operations
Adding/ Changing
element of an Array
Finding the length of an
Array
Array ConcatenationArray Concatenation
www.edureka.co/python
Finding the length of an Array www.edureka.co/python
❑ Length of an array is the number of elements that are actually present in an array.
❑ You can make use of len() function to achieve this.
❑ The len() function returns an integer value that is equal to the number of elements present in that array.
Finding the length of an Array
www.edureka.co/python
Lengthofanarrayisdeterminedusingthelen()functionasfollows:
Finding the length of an Array
import array as arr
a=arr.array('d', [1.1 , 2.1 ,3.1] )
len(a)
len(array_name)
Output- 3
SYNTAX:
www.edureka.co/python
Adding elements to an Array
www.edureka.co/python
js
Insert()extend()append()
Used when you want to add
a single element at the end
of an array.
Used when you want to add
more than one element at
the end of an array.
Used when you want to add
an element at a specific
position in an array.
Functions used to add elements to an Array:
Adding elements to an Array
www.edureka.co/python
Thecodesnippetbelowimplementstheappend(),extend()andinsert() functions:
Adding elements to an Array
Array a= array('d', [1.1, 2.1, 3.1, 3.4])
Array b= array('d', [2.1, 3.2, 4.6, 4.5,
3.6, 7.2])
Array c=array('d', [1.1, 2.1,3.4, 3.1])
import array as arr
a=arr.array('d', [1.1 , 2.1 ,3.1] )
a.append(3.4)
print("Array a=",a)
b=arr.array('d',[2.1,3.2,4.6])
b.extend([4.5,3.6,7.2])
print("Array b=",b)
c=arr.array( 'd' , [1.1 , 2.1 ,3.1] )
c.insert(2,3.4)
print(“Arrays c=“,c)
OUTPUT-
www.edureka.co/python
Removing elements of an Array www.edureka.co/python
Removing elements of an Array
js
pop() remove()
Used when you want to
remove an element and
return it.
Used when you want to
remove an element with a
specific value without
returning it.
Functions used to remove elements of an Array:
www.edureka.co/python
Thecodesnippetbelowshowshowyoucanremoveelementsusingthesetwofunctions:
import array as arr
a=arr.array('d', [1.1, 2.2, 3.8, 3.1, 3.7])
print(“Popping last element”,a.pop())
print(“Popping 4th element”,a.pop(3))
a.remove(1.1)
print(a)
Popping last element 3.7
Popping 4th element 3.1
array('d', [2.2, 3.8])
OUTPUT-
Removing elements of an Array
www.edureka.co/python
Array Concatenation
www.edureka.co/python
Arrayconcatenation canbedoneasfollowsusingthe+symbol:
Array Concatenation
import array as arr
a=arr.array('d',[1.1 , 2.1 ,3.1,2.6,7.8])
b=arr.array('d',[3.7,8.6])
c=arr.array('d’)
c=a+b
print("Array c = ",c)
Array c= array(‘d’, [1.1, 2.1, 3.1, 2.6,
7.8, 3.7, 8.6])
OUTPUT-
www.edureka.co/python
Slicing an Array
www.edureka.co/python
Slicing an Array
import array as arr
a=arr.array('d',[1.1 , 2.1 ,3.1,2.6,7.8])
print(a[0:3])
OUTPUT -
array(‘d’, [1.1, 2.1, 3.1])
An array can be sliced using the : symbol. This returns a range of elements that we have
specified by the index numbers.
www.edureka.co/python
Looping through an Array
www.edureka.co/python
js
for while
Iterates over the items of an
array specified number of
times.
Iterates over the elements
until a certain condition is met.
We can loop through an array easily using the for and while loops.
Looping through an Array
www.edureka.co/python
Some of the for loop implementations are:
import array as arr
a=arr.array('d', [1.1, 2.2, 3.8, 3.1, 3.7])
print("All values")
for x in a:
print(x)
Allvalues
1.1
2.2
3.8
3.1
3.7
OUTPUT-
Looping through an Array using for loop
www.edureka.co/python
Example for while loop implementation
Looping through an Array using while loop
import array as arr
a=arr.array('d', [1.1, 2.2, 3.8, 3.1, 3.7])
b=0
while b<len(a):
print(a[b])
b=b+1
1.1
2.2
3.8
3.1
3.7
OUTPUT-
www.edureka.co/python
www.edureka.co/python

More Related Content

What's hot

Python array
Python arrayPython array
Python array
Arnab Chakraborty
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Arrays
ArraysArrays
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Python set
Python setPython set
Python set
Mohammed Sikander
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
Lalitkumar_98
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Array ppt
Array pptArray ppt
Array ppt
Kaushal Mehta
 

What's hot (20)

Python array
Python arrayPython array
Python array
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Arrays
ArraysArrays
Arrays
 
Linked list
Linked listLinked list
Linked list
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Python set
Python setPython set
Python set
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
 
Python list
Python listPython list
Python list
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
2D Array
2D Array 2D Array
2D Array
 
Array ppt
Array pptArray ppt
Array ppt
 

Similar to Arrays In Python | Python Array Operations | Edureka

STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
SivaSankar Gorantla
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
Edureka!
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
Abbott
 
Collections framework
Collections frameworkCollections framework
Collections framework
Anand Buddarapu
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
MuhammadSubtain9
 
F# array searching
F#  array searchingF#  array searching
F# array searching
DrRajeshreeKhande
 
Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)
Abbott
 
Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
DrRajeshreeKhande
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
Intro C# Book
 
Any Which Array But Loose
Any Which Array But LooseAny Which Array But Loose
Any Which Array But Loose
michael.labriola
 
numpy.pdf
numpy.pdfnumpy.pdf
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
ARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptxARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptx
DarellMuchoko
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6dplunkett
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
info309708
 

Similar to Arrays In Python | Python Array Operations | Edureka (20)

STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Array properties
Array propertiesArray properties
Array properties
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
 
Collections framework
Collections frameworkCollections framework
Collections framework
 
Data structures
Data structuresData structures
Data structures
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
 
F# array searching
F#  array searchingF#  array searching
F# array searching
 
Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)Data structure lecture 2 (pdf)
Data structure lecture 2 (pdf)
 
Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
Any Which Array But Loose
Any Which Array But LooseAny Which Array But Loose
Any Which Array But Loose
 
numpy.pdf
numpy.pdfnumpy.pdf
numpy.pdf
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
ARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptxARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptx
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 

More from Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

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
 
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
 
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
 
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
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
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
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
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
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
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
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 

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
 
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
 
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
 
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...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
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 Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.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
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
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...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 

Arrays In Python | Python Array Operations | Edureka

  • 1.
  • 2. What is an Array? How to Create an Array in Python? Is Python List same as an Array? Basic Array Operations • Finding the length of an Array • Addition • Removal • Concatenation • Slicing • Looping Accessing Array Elements www.edureka.co/python
  • 3. What is an Array? www.edureka.co/python
  • 4. What is an Array? www.edureka.co/python → a a[0] a[1] a[2] a[3…98] a[99] 1 2 3 … 100 Var_Name Values → Index → Basic structure of an Array: An array is basically a data structure which can hold more than one value at a time. It is a collection or ordered series of elements of the same type.
  • 5. Is Python List same as an Array? www.edureka.co/python
  • 6. Is Python List same as an Array? Python Arrays and lists have the same way of storing data. Arrays take only a single data type elements but lists can have any type of data. Therefore, other than a few operations, the kind of operations performed on them are different. www.edureka.co/python
  • 7. How to create Arrays in Python? www.edureka.co/python
  • 8. Arrays in Python can be created after importing the array module. How to create Arrays in Python? → from array import * USING * 3 → import array → import array as arr WITHOUT ALIAS 1 USING ALIAS 2 www.edureka.co/python
  • 9. Accessing Array Elements www.edureka.co/python
  • 10. ❑ Access elements using index values. ❑ Indexing starts at 0 and not from 1. Hence, the index number is always 1 less than the length of the array. ❑ Negative index values can be used as well. The point to remember is that negative indexing starts from the reverse order of traversal i.e from right to left. www.edureka.co/python a[2]=3 Example: a[2]=3 Accessing Array Elements
  • 11. Basic Array Operations www.edureka.co/python
  • 12. Operations Removing/ Deleting elements of an array Slicing Looping through an Array Basic Array Operations Adding/ Changing element of an Array Finding the length of an Array Array ConcatenationArray Concatenation www.edureka.co/python
  • 13. Finding the length of an Array www.edureka.co/python
  • 14. ❑ Length of an array is the number of elements that are actually present in an array. ❑ You can make use of len() function to achieve this. ❑ The len() function returns an integer value that is equal to the number of elements present in that array. Finding the length of an Array www.edureka.co/python
  • 15. Lengthofanarrayisdeterminedusingthelen()functionasfollows: Finding the length of an Array import array as arr a=arr.array('d', [1.1 , 2.1 ,3.1] ) len(a) len(array_name) Output- 3 SYNTAX: www.edureka.co/python
  • 16. Adding elements to an Array www.edureka.co/python
  • 17. js Insert()extend()append() Used when you want to add a single element at the end of an array. Used when you want to add more than one element at the end of an array. Used when you want to add an element at a specific position in an array. Functions used to add elements to an Array: Adding elements to an Array www.edureka.co/python
  • 18. Thecodesnippetbelowimplementstheappend(),extend()andinsert() functions: Adding elements to an Array Array a= array('d', [1.1, 2.1, 3.1, 3.4]) Array b= array('d', [2.1, 3.2, 4.6, 4.5, 3.6, 7.2]) Array c=array('d', [1.1, 2.1,3.4, 3.1]) import array as arr a=arr.array('d', [1.1 , 2.1 ,3.1] ) a.append(3.4) print("Array a=",a) b=arr.array('d',[2.1,3.2,4.6]) b.extend([4.5,3.6,7.2]) print("Array b=",b) c=arr.array( 'd' , [1.1 , 2.1 ,3.1] ) c.insert(2,3.4) print(“Arrays c=“,c) OUTPUT- www.edureka.co/python
  • 19. Removing elements of an Array www.edureka.co/python
  • 20. Removing elements of an Array js pop() remove() Used when you want to remove an element and return it. Used when you want to remove an element with a specific value without returning it. Functions used to remove elements of an Array: www.edureka.co/python
  • 21. Thecodesnippetbelowshowshowyoucanremoveelementsusingthesetwofunctions: import array as arr a=arr.array('d', [1.1, 2.2, 3.8, 3.1, 3.7]) print(“Popping last element”,a.pop()) print(“Popping 4th element”,a.pop(3)) a.remove(1.1) print(a) Popping last element 3.7 Popping 4th element 3.1 array('d', [2.2, 3.8]) OUTPUT- Removing elements of an Array www.edureka.co/python
  • 23. Arrayconcatenation canbedoneasfollowsusingthe+symbol: Array Concatenation import array as arr a=arr.array('d',[1.1 , 2.1 ,3.1,2.6,7.8]) b=arr.array('d',[3.7,8.6]) c=arr.array('d’) c=a+b print("Array c = ",c) Array c= array(‘d’, [1.1, 2.1, 3.1, 2.6, 7.8, 3.7, 8.6]) OUTPUT- www.edureka.co/python
  • 25. Slicing an Array import array as arr a=arr.array('d',[1.1 , 2.1 ,3.1,2.6,7.8]) print(a[0:3]) OUTPUT - array(‘d’, [1.1, 2.1, 3.1]) An array can be sliced using the : symbol. This returns a range of elements that we have specified by the index numbers. www.edureka.co/python
  • 26. Looping through an Array www.edureka.co/python
  • 27. js for while Iterates over the items of an array specified number of times. Iterates over the elements until a certain condition is met. We can loop through an array easily using the for and while loops. Looping through an Array www.edureka.co/python
  • 28. Some of the for loop implementations are: import array as arr a=arr.array('d', [1.1, 2.2, 3.8, 3.1, 3.7]) print("All values") for x in a: print(x) Allvalues 1.1 2.2 3.8 3.1 3.7 OUTPUT- Looping through an Array using for loop www.edureka.co/python
  • 29. Example for while loop implementation Looping through an Array using while loop import array as arr a=arr.array('d', [1.1, 2.2, 3.8, 3.1, 3.7]) b=0 while b<len(a): print(a[b]) b=b+1 1.1 2.2 3.8 3.1 3.7 OUTPUT- www.edureka.co/python