From the zero-learning python Hello World_python

Source: Internet
Author: User
Tags in python

The simple ' Hello world! '

Python command line

If you've already installed Python, enter it on the Linux command line:

Copy Code code as follows:

$python

Will go directly to Python. Then, at the command line prompt >>> after, enter:

Copy Code code as follows:

>>>print (' Hello world! ')

You can see and then output on the screen:

Copy Code code as follows:

Hello world!

Print is a commonly used function that outputs a string in parentheses.

(in Python 2.x, print can also be a keyword that can be written in print ' Hello world! ', but it won't work in 3.x)
Write a little program

Another way to use Python is to write a Python program. Write a. py end file, such as hello.py, with a text editor

Write the following in hello.py and save:

Copy Code code as follows:

Print (' Hello world! ')

Exit the text editor, and then enter at the command line:

Copy Code code as follows:

$python hello.py

To run hello.py. You can see Python then output

Copy Code code as follows:

Hello world!

Script

We can also change the Python program hello.py into an executable script that executes directly:

Copy Code code as follows:

#!/usr/bin/env python

Print (' Hello world! ')

The permissions for the above program need to be modified to be executable:

Copy Code code as follows:

chmod 755 hello.py

And then on the command line, enter

Copy Code code as follows:

./hello.py

You can run it directly.
Summarize

Print

Command-line mode: Run Python, enter commands at the command line, and execute.

Program mode: Write a Python program and run it.

Related Article

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.