-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArray.py
More file actions
44 lines (32 loc) · 1.06 KB
/
Array.py
File metadata and controls
44 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Create an array
cars = ["Ford", "Volvo", "BMW"]
print(cars)
#Access the Elements of an Array
x = cars[0]
print(x)
#The Length of an Array
x = len(cars)
print(x)
#Looping Array Elements
for x in cars:
print(x)
#Adding Array Elements
cars.append("Honda")
print(cars)
#Removing Array Elements
cars.pop(1)
print(cars)
# Array Methods
# Python has a set of built-in methods that you can use on lists/arrays.
# Method Description
# append() Adds an element at the end of the list
# clear() Removes all the elements from the list
# copy() Returns a copy of the list
# count() Returns the number of elements with the specified value
# extend() Add the elements of a list (or any iterable), to the end of the current list
# index() Returns the index of the first element with the specified value
# insert() Adds an element at the specified position
# pop() Removes the element at the specified position
# remove() Removes the first item with the specified value
# reverse() Reverses the order of the list
# sort() Sorts the list