Python Basic notes (i)

Source: Internet
Author: User

1. Python's suffix can be arbitrary in python for a single python file. But if this Python file needs to be imported, if it is not. PY will be faulted. Therefore, in general, the suffix of the Python file is. py

2, is used in Linux./file. py requires the interpreter path in the first line of the document

#!/usr/bin/env/python

3. The Code of the Declaration document is Utf-8

#-*-Coding:utf-8-*-

4, the output function of Python print

Print (' Hello ')

A variable of any type can be connected in parentheses and output the contents of the variable

5. Single-line comment in Python use the "pound" multiline comment using the triple quotation mark "" or "" "

#这是一段单行注释 "This is a multiline comment" "" "" This is a multiline comment ""

  

6, the input of Python uses the input method to manipulate

Value = input (' Hint message: ')

The program will stay here waiting for the user to enter the user input after the completion of the user input content assigned to value regardless of what the user input is the str type.

7. In Python, variable names can only be named by letters, numbers, and underscores. and cannot be preceded by a number. And you can't repeat it with the keywords in python, it's best not to repeat it with Python built-in (practice).

8. If statement in Python

If condition:    a block of code that satisfies execution ... elif condition: the    elif condition satisfies the code block of execution ... else: the    if condition and the condition in elif do not meet when the code block #只要有一个条件满足. The following judgment will not be executed.

Elif and else are optional in the preceding code. Elif can have a number of. But must be in the middle of if and else

":" (colon) represents one of the following code block code blocks inside code indented to represent the same indentation represented within the same code block

If statements can be nested using multiple layers

If elif else is within the same indentation. Represents a set of if

Add: Pass keyword

"If 1==1:                 #如果这样使用会报错. If nothing is done using the PASS keyword. else:    print (' 1=1 ') #应该这样执行. If 1==1:    passelse:    print (' 1=1 ')

9. Data type of Python.

String: A string is used in quotation marks.

str1 = ' ABCDEFG ' str2 = ' I am a string ' STR3 = ' ' I am also a string ' ' STR4 = ' "" I am still a string "" "

  

The addition of strings: concatenation of strings

Fist_name = ' Zhang ' last_name = ' Jiashun ' name = Fist+last_name #name就会等于zhangjiashunprint (name)    

Multiplication of strings: Indicates the number of occurrences of a string

A = ' 123 ' B = A * 3print (b)     #会输出 123123123

  

Integer type: A number that does not use quotation marks and does not have a decimal point

A = 10b = 20c = a + BC = A-BC = A * BC = 100/10C = 2 * * 4              #2的4次幂c = 8%             #39除以8的余数c = 8              #地板除    3 9 divided by eight quotient (rounded down)

10. While loop

  

#该循环为死循环 while 1==1:     #条件成立进入代码块    print (' OK ')     #执行完代码块内最后一条语句后在次判断while条件是否成立

  

Count = 0while Count <:    print (count)    count = count + 1    #count自身增加1后再次判断while条件.

  

    

Python Basic notes (i)

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.