This article mainly introduces the basic python tutorial HelloWorld !, This article describes the example of HelloWorld output in the command line, in the file, and in the script file. For more information, see
Python command line
If you have installed Python, enter the following command in the Linux Command Line:
The Code is as follows:
$ Python
Directly go to python. Then, at the command line prompt >>>, enter:
The Code is as follows:
>>> Print ('Hello World! ')
You can see that, and then output on the screen:
The Code is as follows:
Hello World!
Print is a common function, which is a string in the output brackets.
(In Python 2.x, print can also be a keyword and can be written as print 'Hello World! ', But this does not work in 3.x)
Write a small program
Another way to use Python is to write a Python program. Use a text editor to write a file ending with. py, such as hello. py.
Write and save the following in hello. py:
The Code is as follows:
Print ('Hello World! ')
Exit the text editor and enter:
The Code is as follows:
$ Python hello. py
To run hello. py. You can see the subsequent output of Python.
The Code is as follows:
Hello World!
Script
We can also change the Python program hello. py to an executable script and execute it directly:
The Code is as follows:
#! /Usr/bin/env python
Print ('Hello World! ')
You need to modify the permissions of the above program to execute:
The Code is as follows:
Chmod 755 hello. py
Then, enter
The Code is as follows:
./Hello. py
You can run it directly.
Summary
The Code is as follows:
Print
Command Line Mode: Run Python and enter the command in the command line and execute it.
Program mode: Write and run a Python program.