Python first day, python first day

Source: Internet
Author: User

Python first day, python first day

This is something about Python knowledge learned the day before yesterday.

1. Python is a strongly explanatory language.

In Python, you do not need to define the type of a variable. You need to check the type of the variable before running. However, once the type of the variable is determined, if you do not use force conversion to another type, the variable type will not change. If the string type is not converted to an int type, it is not converted to an int type unless the int type is forcibly converted ). Python is an explanatory language, and the source code cannot be encrypted. If you want to encrypt part of it, you can compile it in C language and reference it. If you want to encrypt all the data, compile it in another language.

2. Define Variables

If ";" is not found in Python, you can directly wrap the line after the statement ends. The variable definition method is as follows:

Name = "guoying" # defines variables. strings must be enclosed in quotation marks.

Print (name) # print the variable. () is added after print in Python3, not in Python2.

3. conditional statements and cyclic statements

1. if Condition Statement

If true:

1 + 2 = 3

Elif true:

1 + 3 = 4

Else:

1 + 5 = 6

In Python, if is followed by ":", followed by "else if", only "elif", and forced indent in Python. if you do not indent, an error is reported. The purpose is to make the structure clear and clear.

2. while and for Loops

Python has the while and for loops.

While true:

1 + 3 = 4

Print (4)

This is an endless loop, and the operation will always output 4; unless break is added, the entire loop is ended.

For I in range (10 ):

Print (I)

Obtain. A total of 10 cycles. Range (, 2) indicates that the cycle starts from 0, and the step size is 2. The result is 0, 2, 4, 6, and 8.

Continue indicates that the following loop is not continued and a new loop is started.

For example, for I in range (10 ):

If I> 5:

Continue

Else:

Print ("Hello World !")

This code will only output 6 Hello World! , After I = 6, only the loop repeats until the end of the loop.

 

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.