forked from amirkhan1092/python38-GLA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsec3.py
More file actions
178 lines (118 loc) · 2.11 KB
/
Copy pathsec3.py
File metadata and controls
178 lines (118 loc) · 2.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# string
# initialization
a = 'hello'
print(len(a), type(a))
# element indexing
d = a[-6]
print(d, type(d))
# slicing : substring from string data
h = 'hello world'
d = h[-3::1]
print(d, type(d))
# type cast with string
# number
k = int('1010',8)
print(k, type(k))
k = float('2.4')
print(k, type(k))
# list
st = '[2, 43, 4]'
lst = list(st)
print(lst, type(lst))
lst2 = eval(st)
print(lst2, type(lst2))
hello = 10
k = eval('hello')
print(k, type(k))
# list from from user
lst = eval(input('enter the list '))
print(lst)
# method
# split
k = '213 43 443 23 23 212'
out = k.split()
print(out, type(out))
# capitalize()
k = '2hello world'
out = k.capitalize()
print(out)
# upper
k = '2hello world'
out = k.upper()
print(out)
# output 2HELLO WORLD
# lower
k = '2Hello world'
out = k.lower()
print(out)
# output 2hello world
# center
k = 'hello6'
out = k.center(11, '*')
print(out)
# output hello*****
# rjust
k = 'hello'
out = k.rjust(10, '*')
print(out)
# rjust
k = 'hello'
out = k.ljust(10, '*')
print(out)
# zfill
k = '-12232'
out = k.zfill(10)
print(out)
# output -000012232
# encode
k = 'helloϪ'
out = k.encode('utf', errors='replace')
print(out, type(out))
out2 = out.decode('utf')
print(out2, type(out2))
# maketrans, translate
k = 'hello world'
intab = 'abcdef'
outab = '123456'
trans = str.maketrans(intab, outab)
out = k.translate(trans)
print(out)
# list
# list creation
a = [] # list format
a = list() # using constructor
print(a) # []
# init a list with single object
a1 = [10]
a2 = ['hello']
a3 = [[3,4]]
# accessing the elements
# 1. indexing : value at given position
k = [2, 43, 'hello', 1+3J]
d = k[-1]
print(d, type(d)) # (1+3j) <class 'complex'>
# 2. slicing: values at given range
k = [2, 43, 'hello', 1+3J]
d = k[10:1:-1]
print(d, type(d))
# other operation
# membership operator
ls = [2, 4, 5]
i = 3
out = i in ls
print(out) # False
out = i not in ls
print(out) # True
# concat
l1 = [2, 5]
l2 = [3]
l = l1 + l2
print(id(l))
l += [10, 11]
print(id(l))
print(l, type(l)) # [2, 5, 3, 8] <class 'list'>
# multiplication
ls = [2, 5]
out = ls*2
print(out)
# methods in list