03. Getting Started
Lets run our first python program “Hello Python”. You can make your program by simple test editor or Python IDE like Visual Code editor.
First program by simple text editor Notepad
Lets see how you can make and run your first Python program using Notepad and command prompt:
Create a folder called test at c: drive.
Go to c:\test folder using >cd c:\test command.
Create a file Hello.py using any text editor like Notepad.
Extension of file must be .py
Type print statement in this file:
print(“Hello World”)
Save the file in c:\test folder.
Run your program using following command
c:\test>python Hello.py
It will print “Hello Python” at command prompt .
If you are able to see “Hello Python” at command prompt then congratulations, you have run your first Python program.
Program by Visual Code IDE
Lets see how you can run your first Python program using command prompt
If you want to run your python programs in Visual Studio Editor Python is installed otherwise editor will ask to install python to work in.
To create your programs simply click on the
menu File > New File.
Create a file Hello.py using any Python editor like Visual Editor Code.Type print statement in this file:
print(“Hello Python”)
After that just type python filename.py and hit enter to run your program.
c:\test>python filename.py
It will print Hello Python at Terminal then congratulations you have created and run your first program.
Execution Mode
Python is an interpreted programming language. Python source codes are compiled into bytecode as a .pyc file, and this bytecode can be interpreted.
There are two modes to execute programs in Python:
Interactive Mode
Script Mode
Interactive Mode:
You can execute python statements or expressions directly at Python prompt without storing it in a script file. You can start python prompt by execute c:\python command then you can run a statement or execute an expression:
Here is example to start Python prompt
c:\>python
It will display
Python 3.6.0a1 (v3.6.0a1:5896da372fb0, May 17 2016, 16:07:03) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
Now print "Hello" by executing statement print("Hello"):
>>> print("Hello")
Hello
>>>
It will display Hello in next line at python prompt:
Now execute an expression:
>>> 2+2
4
>>>
Do whatever you want to do with Python prompt.
Scripting Mode:
In order to execute a logic path, you can store set of python statements in a file. File will have extension .py. It is called scripting file.
We are assuming that Hello.py is the script file that has following statements:
#Hello.py
print("Hello");
print("This is my first program");
print("File name is Hello.py");
You can execute this script file with python interpreter by specifying name of the file next to the interpreter:
C:> python Hello
It will display following output