-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrepawksed_with_python.py
More file actions
38 lines (33 loc) · 939 Bytes
/
grepawksed_with_python.py
File metadata and controls
38 lines (33 loc) · 939 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
a="hello buddy"
print(a[:5])
print(a[6:11])
print(a[0:11:2]) # last number is to jump by char
print(a[6:] + a[:6])
print(a[-4:] + a[:-3])
print(a[2::2])
print(a[::2])
print("=========")
tim = '16:30:10'
hrs, min, sec = tim.split(':')
print(hrs) ; print(min) ; print(sec)
print(tim.split(':', 1)) # split() only once
print(tim.split(':'))
print(tim.rsplit(':', 1)) #reverse split
print(tim.partition(':')) # partition can only do one split. it will presrive the delimiter and also put the output in tuple
print(tim.rpartition(':')) # rpartition is same as partition but reverse order
print("=========")
mystr="lotto"
print(mystr.replace('lo', 'ho'))
t = "mytest with some somspace"
print(t.replace(" ",""))
print(max(t))
print(len(t))
print(t.count("som")) ; print(t.count("some"))
print(t.index("t"))
d = {"one": 1, "two": 2, "three": 3, "four": 4}
print(list(d.values()))
print(list(d))
d["one"] = 42
print(d)
del d["two"]
print(d)