user3505931
user3505931

Reputation: 269

Where do I receive print commands in Python

I have a simple python program:

 print 'hi'

Where do I execute this to receive the print statement? Excuse my ignorance, I am just learning python.

Upvotes: 0

Views: 59

Answers (4)

sundar nataraj
sundar nataraj

Reputation: 8702

Open python IDLE in windows or just type python in terminal that

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Sundar>python
Python 2.7.5 Stackless 3.1b3 060516 (default, May 21 2013, 17:59:42) [MSC v.1500
 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hi'
hi
>>>

if u type that u get the response.

Adddtionally : there are lot resources and methods

  1. create a file something.py and in command line u move to loaction where u saved python file and type python something.py

    1. u can do online check this site repl

Upvotes: 0

user3515719
user3515719

Reputation: 1

I've found the best way for a new user to learn Python is to use IDLE, which comes with the Python installation. Here is a simple and easy explanation on how to get started:

http://www.annedawson.net/Python_Editor_IDLE.htm

Upvotes: 0

skeryl
skeryl

Reputation: 5315

Please see this documentation on using the python interpreter: https://docs.python.org/2/tutorial/interpreter.html

first,

either add the path to your Python interpreter into your environment variables, or navigate to that path (usually c:\Python27\python.exe on windows)

then,

type "python" into the command prompt.

Doing so will start the python interpreter and will look something like this:
python interpreter

then you just type in your command:
enter image description here

Upvotes: 0

Burhan Khalid
Burhan Khalid

Reputation: 174672

You have a few options:

  1. You can save it in a file. Then run python yourfile.py to execute the command. The typical file extension for Python source code is .py.

  2. You can run the Python interpreter. This is a way to quickly test Python code without having to save it to a file. Simply type python and you will see a few lines telling you the version of your Python interpreter followed by >>>, which is the interpreter prompt. Any Python statement you type here is immediately executed and the results printed out:

    burhan@sandbox:~$ python
    Python 2.7.3 (default, Jan  2 2013, 16:53:07)
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print 'hi'
    hi
    >>>
    

    To exit the interpreter, type quit().

  3. A third way is to use the -c flag of the Python command. This tells Python to immediately execute the code following the -c flag, like this:

    burhan@sandbox:~$ python -c 'print "hi"'
    hi
    

Upvotes: 2

Related Questions