Python executes "Hello World" program-003

Source: Internet
Author: User
Tags python script

How Python is executed

1. Execute with python command

(1) Create a file hello.py file under Linux and enter

Print ("Hello world!")

(2) then execute the command: Python hello.py, output result

[Email protected] ~]# vim hello.py

[email protected] ~]# cat hello.py

Print ("Hello world!")

[email protected] ~]# python hello.py

Hello world!

[Email protected] ~]#

2. Specify interpreter execution

(1) When we execute hello.py in the first step, we explicitly point out that the Python interpreter executes the

(2) If we want to execute a python script like executing a shell script, we need to specify the interpreter in the script:./hello.py

[Email protected] ~]# vim hello.py

[email protected] ~]# cat hello.py

#!/usr/bin/env Pythn

Print ("Hello world!")

[Email protected] ~]# chmod +x hello.py #赋予脚本执行权限

[Email protected] ~]# vim hello.py

[Email protected] ~]#./hello.py

Hello world!

[Email protected] ~]#

3. Execute in the interactive device

(1) We can directly invoke Python's own interactive runtime code

[[email protected] ~]# python

Python 2.6.6 (r266:84292, 18 2016, 15:13:37)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2

Type "Help", "copyright", "credits" or "license" for more information.

>>> print ("Hello world!")

Hello world!

>>> exit ()

[Email protected] ~]#

Python executes "Hello World" program-003

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.