-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython_arrays.py
More file actions
37 lines (28 loc) · 878 Bytes
/
python_arrays.py
File metadata and controls
37 lines (28 loc) · 878 Bytes
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
# Hello World program in Python
print("Python Arrays")
# Arrays are used to store multiple values in one single variable:
# Create an array containing country names:
countries = ["America", "India", "Japan"]
# Access the Elements of an Array
x = countries[0]
print(x)
# Modify the value of the first array item:
countries[0] = "China"
print(countries)
# Return the number of elements in the cars array:
x = len(countries)
print(x)
# Looping Array Elements
for x in countries:
print(x)
# Adding Array Elements
# You can use the append() method to add an element to an array.
countries.append("Africa")
print(countries)
# Removing Array Elements
# You can use the pop() method to remove an element from the array.
countries.pop(1)
print(countries)
# You can also use the remove() method to remove an element from the array.
countries.remove("Japan")
print(countries)