Python Basics Hello world!

Source: Internet
Author: User

Python command line

Assuming you have already installed Python, enter it on the Linux command line:

$ python

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

>>>print (' Hello World ')

You can see it and then output it on the screen:

Hello world!

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

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

Write a small program

Another way to use Python is to write a Python program that uses a text editor to write a. py file that ends with, say, hello.py

Write the following in hello.py, and Save:

Print (' Hello world! ')

Exit the text editor and enter it at the command line:

$python hello.py

To run hello.py. You can see that Python then outputs

Hello world!

Script

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

#! /usr/bin/env python

Print (' Hello world ')

You need to modify the permissions of the above program to be executable:

chmod 755 hello.py

Then, on the command line, enter

./hello.py

Summarize

Print

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

Program mode: Write a Python program and run it.

Python Basics Hello world!

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.