Jun-06-2017, 07:46 PM
Hi All,
I am new to coding
When I run the following code in python2 and python3 I get different outputs
Can someone please explain this phenomenon
I am new to coding
When I run the following code in python2 and python3 I get different outputs
Can someone please explain this phenomenon
>>> a = [1,2,3,4,"hello"] >>> for i in a: ... try: ... print(i) ... i+1 ... print (("i is : %d") %(i)) ... except: ... print ("nope " + i + " is a string") **Python 2 output** 1 2 i is : 1 2 3 i is : 2 3 4 i is : 3 4 5 i is : 4 hello nope hello is a string **Python 3 output** 1 i is : 1 2 i is : 2 3 i is : 3 4 i is : 4 hello nope hello is a string