Python Learning summary Run Python code snippet
Python comes with an interpreter running in a terminal window that tries to run a Python code snippet without having to save and run the entire program.
- >>>print ("Hello Python interpreter!" )
Hello Python interpreter!
Variables and simple data types in Python
- Variable names can contain only letters, numbers, and underscores, and cannot include spaces. The value of the variable can be modified at any time in the program, and Python will always record the latest value of the variable;
- String
- Number: In Python you can perform a plus (+) minus (-) multiplication (*) on an integer (*).
- Floating point number: Python with decimal numbers collectively;
- function str ();
- Comment Identifier: #, the content behind the pound sign is ignored by the Python interpreter;
- >>>0.1+0.1
0.2
- >>>0.2+0.2
0.4
List element modifications, additions, deletions
- Modify the list element to specify the modification name and the element's lead to be modified, and then specify the new value of the element to change;
- Add an element at the end of the list: Method append (); Insert element in list use method: Insert () to add a new element anywhere in the list;
- Delete the element using the DEL statement; remove removes the element based on the value;
*motorcycles=[' ha ', ' yam ', ' su '
Print (motorcycles)
Del Motorcycles[0]
Print (motorcycles)
[' Ha ', ' yam ', ' su ']
[' Yam ', ' su ']
Here we use Del to delete the first element "ha" in motorcycles.
If statements in Python programming
Cars = [' au ', ' bm ', ' Sub ', ' Toyo ']
For car incars:
if car = = ' BM ':
Print (Car.upper ())
Elif:
Print (Car.title ())
While Loop statement
Current_number = 1
While current_number<=5:
Print (Current_number)
Current_number + = 1
Using the break Exit statement
While True:
City=input (Prompt)
If City = = ' Quit ':
Break
Using the continue statement in a loop
The continue statement is used to adjust the remaining statements of the current loop, and then proceed to the next round of loops.
Summary:
Contact this language time is not long, understand is only some fur, Python simple by many people love, programming learning is cumulative, step by step will do better. The above code is the reference book "Python programming from Getting started to practice"
Python Learning Summary