Now this post is about how you can write programs in python 3 programming language.
The Information will be provided in this with an Hello World Program In Python.
Hello World Program in Python Terminal
To Start an Python Terminal You Can Just Open
python.exe from start menu of windows or just write
python in Command Line Shell Like Command-prompt, Powershell, Git Bash or Terminal of Microsoft Windows Operating System.
For Linux or Mac OS the Command Is Same but sometime they comes with
python2 installed already so for correct python running try
python3 command instead of
python if it does not work.
Given Below is Program we are gonna write
print("Hello World") for displaying Hello World.
$ python Python 3.10 (default, June 4 2019, 09:25:04) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>>print("Hello World") Hello World
Unlike othet language it does not need any semicolon at last and neither the
main function is mandatory everywhere.
Hello World Program In Python File
For Running python Program from File just create an text file named
main.py with python program in it, Here we will write
print("Hello World") In It.
and for running the program just run given below commands.
$ python main.py Hello World
There are some additional configuration for file also like for making the python program file as executable and able to run under Operating Systems Like Mac OS We Can Do Below Steps.
By Default the python encodes the Python Text files in utf-8 encoding which you can change if wanted just add
# -*- coding: encoding_name -*- at start of file and also need to add an
Unix shebang line (
#!/usr/bin/env python3.9) before that for running as executable python script if any issue occurred.
Like New file Will Look Like Below
#!/usr/bin/env python3.9 # -*- coding: utf-8 -*- print("Hello World")
and also before running the file change permissions of file with commands
chmod +x main.py.
I Know I Maybe Wrote too Much thing for an Hello World Program of Python But Most of the Given Details I Found on https://docs.python.org/3/tutorial/interpreter.html
Thanks for reading until here.