I typed up the examples he used while teaching since we don't have the handouts. This might help to get a better understanding of what he was doing. Everything is commented out also, so don't forget to remove the pound sign before playing. ^_^ Hopefully I typed it all correctly, I haven't played around with it yet.
ETA or you can just go to the lecture video at the MIT website and they have the handout right there.
Examples of overloading 3*4 3*'ab' 'a' + 'bcd' 3 + 'ab' str(3)+'ab' 'a'<3 4<'3' '4'<'3' The code he used
##x=3 #create variable x and assign value 3 to it ##x=x*x # bind x to value 9 ##print x ##n = raw_input('Enter a number; ') ##print n ##print n/n
##x=15 ##y=5 ##z=11 ##print x,y,z ###Is this right? ##if x< y: ## if x< z : print 'x is least' ## else: print 'z is least' ##else: print 'y is least' ## ##if x < y and x < z : print 'x is least' ##elif y < z : print 'y is least' ##else: print 'z is least'
Examples used in Lecture
Date: 2009-11-14 12:06 pm (UTC)ETA or you can just go to the lecture video at the MIT website and they have the handout right there.
Examples of overloading
3*4
3*'ab'
'a' + 'bcd'
3 + 'ab'
str(3)+'ab'
'a'<3
4<'3'
'4'<'3'
The code he used
##x=3 #create variable x and assign value 3 to it
##x=x*x # bind x to value 9
##print x
##n = raw_input('Enter a number; ')
##print n
##print n/n
##x=15
##if (x/2)*2 == x:
## print 'Even'
##else: print 'Odd'
##x=15
##if (x/2)*2 == x: print 'Even'
##else: print 'Odd'
##z='b'
##if 'x' < z :
## print 'Hello'
## print 'Mom'
##if 'x'< z :
## print 'Hello'
##print 'Mom'
##x=15
##y=5
##z=11
##print x,y,z
###Is this right?
##if x< y:
## if x< z : print 'x is least'
## else: print 'z is least'
##else: print 'y is least'
##
##if x < y and x < z : print 'x is least'
##elif y < z : print 'y is least'
##else: print 'z is least'
##y=0
##x=3
##itersLeft = x
##while (itersLeft>0):
## y= y+x
## itersLeft = itersLeft -1
###print 'y =',y,',intersLeft=',intersLeft
##print y
##x=10
##i=1
##while(i<x): ## if x%i == 0: ## print 'divisor ',i ## i = i+1 ##x = 10 ##for i in range(1,x): ## if x%i == 0: ## print 'divisor ',i
hqFbGesiTVFUz
Date: 2012-01-09 03:48 am (UTC)