Tutorial Outline
Python Basic Syntax
Python Function Syntax
Python Hello World Program
Python Basic Syntax
Python syntax can be executed by writing directly in the command line.
Example: >>> print (“Hello, Python World!\n”)
Hello, Python World!
-
Or
By creating a Python file on the server / local machine, using the .py file extension and running it in the command line.
Example: $ python3 MyFirstProgram.py [Hit Enter]
Python Function Syntax
def main():
# code here
main()
Example: def main():
print (“Hello, Python World!\n”)
main()
Save as: FunctionDemo.py
Execute: $ python3 FunctionDemo.py [Hit Enter]
Output: Hello, Python World!
Python Hello World Program
Program 1: Python Simple Hello World Program
"""
Program: Python 3 program to display the Hello World message on the console screen.
Date: Thu, 21-Oct-2021
@author: Ankur Saxena
Platform: Linux Ubuntu 20.04/x64/Python 3.6/Vim
"""
# Program start
# Print message
print ("Hi, Python World!")
# Program end
"""
Save this file as "HelloPi1.py"
Execute: $ python HelloPi1.py [hit Enter]
Output:
Hi, Python World!
"""
Program 2: Python Hello World Program Using Function
"""
Program: Python 3 program to display the Hello World message on the console screen.
Date: Thu, 21-Oct-2021
@author: Ankur Saxena
Platform: Linux Ubuntu 20.04/x64/Python 3.6/Vim
"""
# Program start
def main():
print ("Hi, Python World!\n")
main()
# Program end
"""
Save this file as "HelloFunction1.py"
Execute: $ python HelloFunction1.py [Hit Enter]
Output:
Hi, Python World!
"""
Previous Tutorial: How To Install PyCharm IDE
0 Comments