Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginning Python user moving from C++ basic questions
#1
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!
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 1,749 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 8,337 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,216 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 743 02-12-2010, 09:07 PM
Last Post: Kharnage
  "==" and "is" in Python Canoris 1 737 02-07-2010, 03:55 PM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 1 Guest(s)