First section Python

Source: Internet
Author: User

Create a file under Linux called hello.py, and enter
1 Print ("Hello world!")
Then execute the command: Python hello.py, output
123 localhost:~ jieli$ vim hello.pylocalhost:~ jieli$ python hello.pyhello world!
When you execute Python hello.py in the previous step of the specified interpreter, it is clear that the hello.py script is executed by the Python interpreter. If you want to execute a python script like executing a shell script, for example:./hello.py, then you need to specify the interpreter in the header of the hello.py file, as follows:
123 #!/usr/bin/env python print "Hello,world"
As a result, execute:./hello.py. PS: Need to give hello.py execute permission before execution, chmod 755 hello.py declaring variable
123 #_ *_coding:utf-8_*_ (declaring font as UTF-8) name = "Alex Li"
The code above declares a variable named: Name, and the value of the variable name is: the "Alex Li" variable defines the rule:
    • Variable names can only be any combination of letters, numbers, or underscores
    • The first character of a variable name cannot be a number
    • The following keywords cannot be declared as variable names
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ') variable assignment
12345678 Name = "Alex Li" name2 = Nameprint (name,name2) name = "Jack" Print (name,name2)
As the result of the execution is Alex Li Alex li/jack Alex Li comment single line comment with #, multiline comment with "" "" "" "" "should show the Python interpreter what code to use to execute the source code, i.e.:
1234 #!/usr/bin/env python (using the Python interpreter) #-*-Coding:utf-8-*-(use UTF-8 encoding to process this program, otherwise it won't work out kanji) print "Hello, World"
Input, providing an entry entry, the following will prompt, what is your name, such as fill in Xuweiwie, final print Hello Xuweiweiname = input ("What is your name?") Print ("Hello" + Name) compiled & interpreted compiled language before the program executes, the program executes a compilation process through the compiler, turning the program into machine language. The runtime does not need to be translated and executes directly. The most typical example is the C language. Interpreted language does not have this compile process, but when the program runs, through the interpreter to the program to explain the line, and then directly run, the most typical example is Rubypython is compiled after the interpretation of the string format output
1234 Name = "Alex" Print ("I am%s"% name) #输出: I am Alex
1234 Name = 234print ("I am%d"% name) #输出: I am 234
PS: String is%s, integer%d, floating-point number%fpython3 is more than python2 a default Chinese character encoding

First section Python

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.