Python learning 2 and python Learning

Source: Internet
Author: User

Python learning 2 and python Learning

I don't want to write it the next day ~~

Come on ~~

--- Condition judgment ---

What is interesting about Python is that there is no () {}, but instead an indent control code block. The following conditions must be met:

Starting from if ~~ (Else if is changed to elif)

-- The input return type is str, which must be converted to int.

 

--- Loop ---

First: for x in...Place each element into a variable.xAnd then execute the indent BLOCK statement.

When you accidentally forget to write the judgment condition:

Type 2: as long as the while condition is met, the loop will continue. If the condition is not met, the loop will exit.

Break and continue

 

Improper use of break and continue may result in logical forks or endless loops.

Execute ctrl + c to exit the program.

 

--- Dict and set ---

-- Dict has never seen it before. Put it in {}, which is similar to Map. Store values as key-value.

Features: 1) Fast insert search speed, not slowing down with the increase of keys;

2) large memory usage

. Pop () delete based on key

The insertion method is quite special. In the figure, DD is the newly inserted data.

There are still many usage cases of dict. Please check it again when necessary ~~

-- Set is similar to dict, but only key is unique.

Add () add element. You can add duplicate elements, but the result is only displayed once.

Remove () delete an element

Set can also perform intersection and merge operations

Set and dict are both immutable objects, because they cannot be judged to be equal.

Ps: str unchanged list variable

 

End of the next day ~~~

Continue to thank Liao Xuefeng for its official website ~~

Let's take a look at the differences between a mutable object and a mutable object.

 

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.