Basic python tutorial-HelloWorld!

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.