Support Forums

Full Version: Beginning Python user moving from C++ basic questions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have taken a c++ programming course and I'm trying to learn python. In C++ I would write something like:

int var = 3;
var = var+1;
cout << var << endl;

and later when I compile and run the program I expect the program to display the number 4. But in Python i wrote:

>>> var=3
>>> var=var+1
>>> print var
4

and to my dismay a 4 pops out right away! So how can write scripts so that they don't start doing things right away?

Also how do I use my Python programs once they're written?( I'm using Ubunu 12.10 and IDLE.)
For instance in for a C++ program, using the Linux terminal I would find the program in my directory, then type:

g++ ./programName.cpp

And if it compiles I would type:

./a.out

And my program would run in the terminal!
You need to write the data into a .py file. Python is an interpreter language. So for example, run the command in terminal "touch test.py", "cat test.py", then type
Code:
v = 3
v = v + 1
print v
End the cat, then type "python test.py"

And it will run XD