top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python Arrays

Writer's picture: Bechir MathlouthiBechir Mathlouthi

An array is a special variable, which can hold more than one value at a time. If you have a list of items (a list of student names, for example), storing the students in single variables could look like this:



student1 = "john"
student2 = "jimmy"
student3 = "chris"

but what if you had not 3 students, but 500 and you want to loop through students and find a specific one


An array can hold many values under a single name, and you can access the values by referring to an index number.


Access the Elements of an Array:

ou refer to an array element by referring to the index number.


Get the value of the first array item:
x = student[5]

The Length of an Array:


Use the len() method to return the length of an array (the number of elements in an array).


Return the number of elements in the students array:
x = len(students)

Looping Array Elements :

You can use the for in loop to loop through all the elements of an array.



Print each item in the cars array:
    for x in cars:
     print(x)

Adding Array Elements :

You can use the append() method to add an element to an array.


Add one more element to the cars array:
students.append("Bechir")

Removing Array Elements :

You can use the pop() method to remove an element from the array.

Delete the second element of the students array:
students.pop(1)


Conclusion :


An array is a collection of items stored at contiguous memory locations, and it allows to manipulate a lot of items

0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page