-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oct10Class.py
207 lines (161 loc) · 3.58 KB
/
Oct10Class.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
### Dict#6.py
states={'Rajasthan':33}
states['Delhi']= 11
states['Punjab']=14
#print states
states['Tamil Nadu']= 64
states['Kerala']= 67
states.update({'Punjab':15})
states.pop("Rajasthan")
for state in states:
print state, states[state]
#####Employee9.py
from Employee import *
class Book():
def __init__(self, name, auther):
self.name=name
self.auther=auther
def getName(self):
return self.name
def getAuthor(self):
return self.auther
class PythonBook(Book):
def __init__(self, name, author):
Book.__init__(self, name, author)
def get_name(self):
print self.getName()
if __name__ == '__main__':
'''
emp=Employee()
emp.callHarish()
'''
p=PythonBook("Learn Python", "Vikram U K")
#print p.getName()
print p.getName()
print p.getAuthor()
###Employee.py
class Employee():
def __init__(self):
print "Hello"
def callHarish(self):
print "Hi harish"
### Functions7.py
def defVal(a, l=[]):
l.append(a)
return l
def defValNone(b, k=None):
if k is None:
k=[]
k.append(b)
return k
for i in range(0,4):
print defVal(i)
#print defValNone(i)
def myFunc(*kw):
for a in enumerate(kw):
print a
def print_everything(*args):
for count, thing in enumerate(args):
print '{0}. {1}'.format(count, thing)
List=[1,2,3,4]
myFunc(List)
print type(List)
ArgList=('apple', 'banana', 'cabbage')
print type(ArgList)
print_everything(ArgList)
### Functions#8.py
def MyFunc(n):
return lambda(n):n*n
List=(1,2,3,4,5)
for i in range(0,3):
print MyFunc(i)
x= MyFunc(2)
print x(-4)
## List#4.py
subjectsin10=['Maths', 'Social', 'English', 'Science']
subjectsin12 =['Physics','Chemistry', 'Maths', 'Bio']
subjectsinGrad =['SOM', 'Comms','Stats']
#allSubjects =subjectsin10+ subjectsin12+ subjectsinGrad
allSubjects=[]
allSubjects.append(subjectsin10)
allSubjects.append(subjectsin12)
allSubjects.append(subjectsinGrad)
#allSubjectsin12, allSubjectsinGrad]
#print allSubjects
allSubjects10Plus2=[]
allSubjects10Plus2.append(subjectsin10)
allSubjects10Plus2.append(subjectsin12)
print allSubjects10Plus2[1][1]
###String#3.py
str1="Python"
str2="hands On Session"
print str1+" "+str2
str3="Fun learning"
print (str1+"!")*3+str3
str4="Hands on Session"
print str4[1:6] ,str4[6:8]
print "Last Four:"+ str4[-4:]+ " ---First Four:"+ str4[0:4]
print str4[:5]
print str4[6:9]
print str4[10:60]
x=(len(str4)-4)
print x
print str4[x:]
### Tuple#5.py
tuple1=(1)
tuple2=(1,)
#print type(tuple1)
#print type(tuple2)
mylist = []
for x in range(5):
mylist.append(x)
mytuple = tuple(mylist)
'''
print mytuple
print type(mylist), type(mytuple)
'''
a=dict(one=1, two=2,three=3)
b={'one': 1, 'two': 2, 'three': 3}
c=dict(zip(['one','two','three'], [1,2,3]))
d=dict([('two',2),('one',1),('three',3)])
e=dict({'three':3, 'one':1, 'two':2})
a==b==c==d==e
'''
def swaps(val1,val2):
val1['one']=val1['one']+ val2['two']
val1['two']=val1['one']- val2['two']
retu
val1=dict(one=1)
val2=dict(two=2)
'''
def swaps(a,b):
a=a+b
b=a-b
a=a-b
return a,b
print swaps(5,4)
### Create#1.py
# !#/bin/python
num1=5
num2=6
sum=0
sum= num1+num2
print sum
a,b,c='Python','version','2.9' #print a,b,c
var1=2.50
var2= "Python training"
var3=[1,2,3,4,5]
print type(var1),type(var2),type(var3)
# print type(var3)
### Datatype#2.py
int1=1
long1= 123456789
float3=1.0E6
print int1+long1
var1='Python'
var2='Tutorial'
type(var1)
print type(var1)
val3={'i':'2'}
print val3
print set(val3)