-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0005_more_strings.py
More file actions
50 lines (40 loc) · 1.14 KB
/
0005_more_strings.py
File metadata and controls
50 lines (40 loc) · 1.14 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
45
46
47
48
49
parrot = 'Norwegian Blue'
print(parrot)
print(parrot[3])
print(parrot[4])
print()
print(parrot[3])
print(parrot[6])
print(parrot[8])
# negative indexing
# like in JS
print()
print()
print(parrot[-11])
print(parrot[-1])
print()
print(parrot[-11])
print(parrot[-8])
print(parrot[-6])
# slicing
# 0 through 6 but not including 6
# just like slice() in JS
print(parrot[0:6]) # Norweg
print(parrot[3:5]) # we
print(parrot[0:9]) # Norwegian
print(parrot[:9]) # Norweg, defaults to the start element of the sequence
print(parrot[10:14]) # Blue
print(parrot[10:]) # Blue, default to the last element of the sequence
print(parrot[:6] + parrot[6:]) # Norwegian Blue
print(parrot[:]) # Norwegian Blue
print(parrot[-4:-2]) # Bl
print(parrot[-4:12]) # Bl
# steps
print(parrot[0:6:2]) # Nre
print(parrot[0:6:3]) # Nw
number = '9,223;372:036 854,775;807'
#print(number[1::4]) # prints all the delimiters
separators = number[1::4]
print(separators)
values = "".join(char if char not in separators else " " for char in number).split()
print([int(val) for val in values]) # [9, 223, 372, 36, 854, 775, 807]