Hello World: Create your First Python Program
Starting Pytthon Interpreter
Following installation, the Python interpreter resides in the designated installation directory. For Windows systems, the typical location is C:\PythonXX, but you have the flexibility to modify this during the installation process. To incorporate this directory into your PATH, you can execute the following command within the command prompt of a DOS box:
You can initiate Python on various systems like Unix, DOS, or any other environment that offers a command-line interpreter or shell window. By entering "python" in the command line, you activate the interpreter in immediate mode, allowing direct input of Python expressions. Upon pressing enter, the interpreter promptly generates the corresponding output.
The classic first program is "Hello, World!" Let’s adhere to tradition. Type in the following and press Enter:
Congratulations!! You have written your first program in Python.
Python Scripting mode
Scripting mode is employed for executing Python programs that are authored within a file using text editors like Notepad. These files are referred to as scripts and can be stored on disk for future utilization. Python scripts possess the .py extension, denoting that the filename concludes with .py. For instance, "myFirstProg.py" is an illustrative example of a Python script filename.
Open a text editor (Notepad) and type in the following program exactly as written:
Save this file as "myFirstProg.py".
To execute this file in script mode we simply write "python myFirstProg.py" at the command prompt.
You should see the line Hello World! as output.
The print() function functions as an instruction to the system, prompting a specific action. Its function nature is discernible through the use of parentheses. When employed, print() instructs the Python interpreter to present or produce the content enclosed within the parentheses. By default, this output is directed to the prevailing terminal window.
Congratulations! You have written the "Hello, World!" program in Scripting mod also.
Conclusion
Creating your first Python program, often the "Hello World" example, involves utilizing the print() function to display text output. By invoking print() with the desired content within the parentheses, you instruct the Python interpreter to showcase the provided text. This fundamental introduction establishes the foundation for Python programming.