Skip the previous chapters to introduce and install and start learning notes from programming.

Source: Internet
Author: User
Tags shebang
3. Step 1

Before learning how to use Script Programming, let's take a look at the python interpreter. Open the command line window, input python in the command line, and press enter to open the python interpreter. You can directly input Python statements or expressions in the python interpreter to execute python. Let's execute the hello World Program, the first program that can be used to learn any language.

Input print 'Hello world! 'in the python interpreter! 'Then press Enter. What is displayed on the screen? That's right. It's Hello world! It's easy. This is Python. If you need to exit Linux, press Ctrl + D, press Ctrl + Z in windows, and then press Enter. What do we enter? This is a python statement. This statement is a print statement.

I think it's okay to run a python statement in the interpreter. Let's take a look at how to compile a Python script. However, before writing a Python script, you 'd better find a text editor or Python ide that belongs to you. If you haven't, go online and find it. Believe me, it is not helpful to use Microsoft notepad.

Okay, now let's turn Hello world into a script.

#! Usr/bin/Python

# Filename: helloworld. py

Print 'Hello world! '

 

Well, it's done. This is our first Python script. we name it helloworld. py. That's right. The suffix of the Python script is py. How is it easy to remember.

We have compiled the script. How can we run it? You can run Python scripts in two ways. The first is to execute the Script: Python script through the command line. If the script is in the current directory, you can directly use the script name. If not, you need an absolute path (complete path ). The second is to directly double-click the script to run the script if the script has the running permission. If you need to use "chmod A + x script" in Linux to add running permissions for the script, this step is not required for Windows, and python can be omitted in the command line. Of course, this is the case that no ide is available. If you use IDE, you can run the script directly by using shortcuts or clicking the button or option.

I think it's time to see what's going on with this script. In python, like most shell scripts, # is used to start with a comment. Therefore, the second line is a comment of this file, this comment tells us that the file name is helloworld. py. What about the first line? This row is not actually a comment line. Don't think I'm a lie. I'm serious. The first line is called shebang line. The following section summarizes Wikipedia:

"In a computer, shebang (also known as hashbang) is a string line consisting of a well number and an exclamation point (#!...), It appears in the first two letters of the text line. When shebang exists in the file, the program loader of Unix-like operating system will analyze the content after shebang, use the content as an interpreter instruction, and call this instruction, the file path containing shebang is used as the parameter of the interpreter."

I don't want to repeat the rest.

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.