-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path02.py
More file actions
29 lines (23 loc) · 709 Bytes
/
02.py
File metadata and controls
29 lines (23 loc) · 709 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
# Array (list) of colors
colors = ["pink", "blue", "red", "green"]
# Print 2nd item in array
print (colors[1])
# Variable
color = 2
# Print variable value
print (color)
# Print 3rd item in array
print (colors[color])
# Add new item to first position
colors.insert(0, "orange")
# Print 3rd item in array
# https://docs.python.org/3/library/string.html#formatspec
print ("1st color is {0} and 2nd is {1}".format(colors[0], colors[1]))
# Reverse item order in array
colors.reverse()
# Delete third item in array
del colors[2]
# Exercise
# 1. Open documentation https://docs.python.org/2/library/array.html and find how to
# add new item to the end of array
# 2. Find how to get count of items in array