Python Forum
Different outputs in Python2 and Python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Different outputs in Python2 and Python3
#1
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

>>> 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
Reply


Messages In This Thread
Different outputs in Python2 and Python3 - by MikeHill - Jun-06-2017, 07:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  format json outputs ! evilcode1 3 1,778 Oct-29-2023, 01:30 PM
Last Post: omemoe277
Sad Migrating of python2 script to python3 zuri 7 1,052 Oct-05-2023, 02:40 PM
Last Post: snippsat
  Migration of Python2 and Python3 using Modernize and Future Rakshan 5 2,596 Oct-05-2023, 08:55 AM
Last Post: zuri
  Formatting outputs created with .join command klairel 2 653 Aug-23-2023, 08:52 AM
Last Post: perfringo
  I have written a program that outputs data based on GPS signal kalle 1 1,200 Jul-22-2022, 12:10 AM
Last Post: mcmxl22
  Why does absence of print command outputs quotes in function? Mark17 2 1,416 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 1,506 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  Combining outputs into a dataframe rybina 0 1,698 Mar-15-2021, 02:43 PM
Last Post: rybina
  ONE input => THREE outputs Tricia279 6 2,707 Jan-14-2021, 08:52 AM
Last Post: perfringo
  python2 python3 messed up : How to fix ? hary 15 8,138 Dec-30-2020, 08:26 PM
Last Post: hary

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020