forked from patrickwolf/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj1_data_structures.py
More file actions
41 lines (35 loc) · 1004 Bytes
/
j1_data_structures.py
File metadata and controls
41 lines (35 loc) · 1004 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
38
39
40
41
'''
@summary: Python Intro - Iterables
'''
# ---------------------------
# string - immutable
# ---------------------------
st = "abc"
st = 'abc'
st = """ multi line
string """
# st[2] = "e" # raises TypeError
# ---------------------------
# tuple - immutable
# ---------------------------
tu = ('spam', 'eggs', 100, 1234.0, (4, 1))
print tu, tu[2]
# tu[2] = "bacon" # raises TypeError
# ---------------------------
# list - mutable
# ---------------------------
a = ['spam', 'eggs', 100, 1234, [4, 1]]
# mutable - change values
print "before", a[3]
a[3] = 345
print "after", a[3]
# ---------------------------
# tuple - slicing
# ---------------------------
tu = (23,51,"abc",5.2)
print tu[:], tu[:2], tu[2:], tu[1], tu[2:3], tu[-1] # (23, 51, 'abc', 5.2) 51 ('abc',) 5.2
# ---------------------------
# list - slicing
# ---------------------------
li = [23,51,"abc",5.2]
print li[:], li[:2], li[2:], li[1], li[2:3], li[-1] # [23, 51, 'abc', 5.2] [23, 51] ['abc', 5.2] 51 ['abc'] 5.2