Pages

Wednesday, April 26, 2017

Python version 2.7 and 3.4 diff

2.7)raw_input("Enter")->str  
  input("enter") ->int/eval
3.4)input("Enter")->str

2.7) print "hello world"      
3.4)print("hello world")

2.7) range(1,11)-mallocs      
   xrange(1,11)-doest malloc  
3.4)list(range(1,11))-mallocs
   range(1,11)-doest malloc

2.7)res=map(fun,arr)
3.4)res=list(map(fun,arr))
       
2.7)list.sort(cmp=None, key=None, reverse=False)
3.4)list.sort(key=None, reverse=False)

2.7) file object              
fob=open("one.txt","r")        
OR
fob=file("one.txt","r")
3.4) io.TextIOWrapper
fob=open("one.txt","r")

2.7) filenotfoud-IOError      
     others     -IOError        
3.4) filenotfound
     -FileNotFoundError
     Invalid operation
     -io.UnsupportedOpceration

2.7) every class should be a derived class of "object" class              
3.4) it is implicitly derived from "object" class

2.7) super(CURRCLASS,self).fn()
3.4) super().fn()

2.7) string is ASCII & Unicode
3.4) by default everything is UNICODE

2.7) res=generator()    
    print res.next()              
    print res.next()              
3.4) res=generator()
    print(res.__next__())
    print(res.__next__())

No comments:

Post a Comment