(from the small turtle 0 Basic Beginner Learning python)
To learn python, you can go through the contents of the Rookie tutorial: http://www.runoob.com/python3/python3-basic-syntax.html
If you want to know how many built-in functions (BIF) Python has, you can enter Dir (__builtins__) (note two crossbar)
The plain lowercase is the built-in function.
The functions of built-in functions can be known through help. Help (Bif's name)
About escaping:
In addition to using the original string, you can use the escape character backslash to precede the string with an English letter R, as follows:
If you want to get a string that spans multiple lines, you need to use a triple quote string, for example:
Conditional branches:
While Loop statement:
Python's data types are: integer, float, character, and so on.
Data type conversions:
Watch out! ~ STR is a built-in function, so do not use STR as the variable name.
The type function can be used to view data types:
The Isinstance function is used to determine whether a data type is:
The division "/" in Python3 is calculated accurately and is accurate to decimals.
"//"
* * is a power operation:
Priority level
Branches and loops:
Example: Enter a score to determine the level
There are several ways:
can be abbreviated as:
Conditional expressions (Ternary operators)
Conditional expressions (Ternary operators)
Assertion (Assert)
Assert this keyword we call "assertion", when the condition behind this keyword is false, the program automatically crashes and throws an Assertionerror exception.
For loop
Example:
Range ():
Grammar:
The BIF has three parameters, two of which are enclosed in brackets, which are optional. Step=1 indicates that the value of the third parameter defaults to 1.
Range The function of this bif is to generate a sequence of numbers starting from the value of the start parameter to the end of the value of the stop parameter.
Array:
Adding elements to the list are: Append (), extend (), insert ()
Append
There can only be one element in the append:
Error!
So the principle of using extend:extend is actually to use a list to extend the list
Insert
Note: The list index value is zero-based.
For a swap of the position of an element in a list, you can use an intermediate variable:
Exchange Success!
Remove an element from the list: Remove (), Del, Pop ()
Remove
Must be delete an existing element, or an error
Del's usage: del is a statement
Pop
List shards (slice)
Using indexed values, we can get an element from the list every time, but what if we take a number of elements at once? You can take advantage of list sharding.
1:3 meaning: Start with an index value of 1 and take 3-1 elements.
Compare:
So visible, member[:] can be used for copies of member arrays!
Python Getting Started notes