2

I created a simple python script which has the following two lines:

a =2
a

When I run this script in Ubuntu terminal (by typing "python3.4 script.py"), nothing is displayed. But when I type the above two commands (or lines) in a python interpreter, the second command ('a') displays the value of the variable 'a', i.e. 2.

My question: Why does the second command ('a') behave differently when run as a part of a script as compared to when run as an individual command in the python interpreter?

1 Answers1

2

You are giving a value of 2 to the variable a.

When you type a in the Python interpreter it will output the representation of your input as repr() would.

That's why entering a returns 2.

Harrison
  • 5,095
  • 7
  • 40
  • 60
  • Even without the variable, entering `2` into the interactive interpreter will `repr` it and spit out `2`. The question was why running the script doesn't have output – OneCricketeer Sep 03 '16 at 01:58