Beginning Python user moving from C++ basic questions - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32) +---- Thread: Beginning Python user moving from C++ basic questions (/showthread.php?tid=27526) |
Beginning Python user moving from C++ basic questions - Vorlondel - 12-24-2012 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! RE: Beginning Python user moving from C++ basic questions - Rhynorater - 01-02-2013 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 And it will run XD |