Why do I learn python?
First, my first language is C/C ++ (Object-Oriented subset ). On the one hand, I chose to learn Python because many people say that python development is highly efficient, so I want to verify it. On the other hand, Eric S. RaymondArticle: How to Become a hacker's recommendation for python. On the other hand, the design philosophy of Python: it is better to use only one method to do one thing, which I agree.
Now, the entry material I selected is a concise Python tutorial. Below are some notes and thoughts on my study, with obvious traces of C and C ++.
Control Structure:
- There is a natural string concept that C does not have.
- I ++ is not supported. I welcome this. ++ Will induceProgramNew Employee makes mistakes. I basically abandoned ++ in C.
- Python does not have a switch. You can use if Elif else to implement the same function.
- While can be followed by an else clause.
- For I in range ():, from 1 to 5, but not 5.
- The break statement can still stop the loop. However, after the loop is stopped, the else block is not executed.
- Continue is the same as before.
- Function input parameters have no type. If the real parameters and the form parameters do not match, how can we avoid them. If the type does not match, the Operation will fail.
- Global can tell the function that the variable is outside the function. However, global variables are not encouraged. It can declare multiple.
- Default parameter: similar to C ++, it is represented by "= value. Unified, it can only set the default parameters for the last parameter.
Data structure:
Dictionary:
A dictionary is similar to a binary tree, but does not know what the dictionary uses internally.Algorithm.
The key value must be unique. If it is not unique, what will happen when it is added? Linux Binary Trees are covered.
Answer: If a key already exists in the dictionary, it will overwrite the original value. It is set. This is consistent with the binary tree in Linux.
Similar to Binary Trees, keys cannot be changed. What are the consequences of a change. At least after the binary tree changes, the structure of this number will be corrupted. Moreover, the compiler cannot detect the vulnerability. Will Python check?
Answer: Yes. An error is prompted during running. Because he does not have the concept of compilation. So...
Can I get a variable as a keyword?
Answer: This is acceptable, and there is no problem with running. But what if I change this keyword?
But what if I change this keyword?
Answer: After the change, the dictionary does not change. It means that he only uses the value of this variable, takes its value as a constant, and uses it as a keyword instead of a variable as a keyword.
Is the dictionary efficiency good? What algorithm is used internally? Binary Tree, hash, or others?
Answer: Hash table.
Can dictionary keys be of different types?
Answer: Yes.
A dictionary is a dict object, a tuples are tuple objects, and list objects are displayed in the list.
Sequence:
Two features of a sequence are index operators and slice operators. One is to get a project, and the other is to get a subsequence.
The list and metadata are sequences.
The sequence starts from zero. This is the same as an array. But he can be a negative number !?
Answer: When a negative number is used, it indicates removing the last element, and-1 indicates the last element.
What is slice?
Answer: Obtains a subsequence in a sequence. For slice, the colon is required, and the number is not required. If there is no number, it indicates starting from or ending from scratch. No number indicates the entire sequence.
Does slice assign values to a new sequence?
Answer: Yes.
What if the retrieved element is out of the range?
Answer: An error occurred while running.
What if the slice is out of the range?
Answer: It was originally thought that an error would occur, but it was not displayed, but it was blank.
List, tuples, and strings are all sequences. You can use the sequence method to operate them.