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.x
And 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.