-
Notifications
You must be signed in to change notification settings - Fork 0
/
Python_Basics.py
166 lines (98 loc) · 2.12 KB
/
Python_Basics.py
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
class newclass () :
def set (self, va, ba) :
self.va = input("please enter value for 'va' = ")
self.ba = input("please enter value for 'ba' = ")
def add (self) :
print self.va
print self.ba
self.res = self.va+self.ba
def disp (self) :
print self.res
# list handling
lis = [3,46,7,3]
li = range(1,21)
# print [x for x in li if x%2==1]
import copy
x = [1,2,3,4]
y = copy.copy(x)
y.append("5")
# print x is y
# print y is y
# exit()
# print lis.pop()
# print lis.append("dfd")
# print lis.index("dfd")
# print lis.insert(1,"asdfasf")
# print lis.sort()
# # print lis.extend(lis)
# print lis.reverse()
# print lis[0:4]
# lis[0:2] = lis
#
# print
# print lis
# string handling
# strr = " bharath krishna "
#
# print strr.title()
# print "a comes", strr.count('a')," times"
# print strr.strip()
# print strr.strip().partition(" ")
# print strr.strip().rpartition(" ")
# print strr.strip().split("h", 2)
# print strr
def args (ga,*tup, **dics) :
print ga," is a str"
print tup
print dics
def unpack (l1,l2,l3,ga,ha,ja) :
print ga,ha,ja
pass
dic = {'ga' : 3, 'ha' : 4, 'ja' : 5}
args(12233, 43,545,5,4,fdf = 343, fdfs=322 )
li = ()
# unpack(**dic)
# obj = newclass()
# obj.set(5,5)
# obj.add()
# obj.disp()
exit(0)
# list comprehension
print [x for x in range(2) if(x > 0) for x in range(3) if x > 1]
list = []
for x in range(2) :
if(x > 0) :
for x in range(3):
if x > 1 :
list.append(x)
# print list
#
# num = 512
# print num << 1
#
#
# print
# s = 'asdf'
# it = iter(s)
#
# print it.next()
# print it.next()
# print it.next()
# print it.next()
exit()
class reverse () :
def __init__ (self, data) :
self.data = data
self.index = len(data)
def __iter__ (self) :
return self
def next (self) :
if self.index == 0 :
raise StopIteration
self.index = self.index - 1
return self.data[self.index]
obj = reverse("bharath")
# print obj
iter(obj)
for ch in obj :
print ch