python full stack development day01

1. Getting to know the computer
CPU: Central processing unit, equivalent to the brain, computing and computing center
Memory: Temporary storage of data (ROM) for the CPU to perform operations
Pros: Fast read speed
Disadvantages: small capacity, high cost, disappears immediately after power failure
Hard Disk: Stores a large amount of data for a long time. 500G, 1T
Advantages: large capacity, low cost, power failure will not disappear
Cons: slow read speed
Operating system: read data from the hard disk to the memory, and then read the data from the memory to the CPU, this process is all deployed by the operating system
windows operating system, linux operating system, mac operating system
2. First acquaintance with python
The founder of python is Guido van Rossum Chinese name: Uncle Gui
3. History of python development (focusing on understanding the origin of python2 and python3)
The difference between python2 and python3:
(2.7 has been gradually approaching 3 for several years from now to 2020, until 2.7 disappears completely in 2020)
python2: The source code is not standardized (some are close to Java, some are close to C)
The source code is confusing and repetitive (the source code is the program that the developer writes to let people use it)
python3: Reorganization of source code, source code specification, pursuit of beauty, clarity, simplicity
4. Types of languages ​​(divided into compiled and interpreted):
Compiled: Compile the code into binary all at once. Then run (write the source file first, then compile it into a bytecode file)
Advantages: high execution efficiency
Disadvantages: slow development efficiency, not cross-platform
The representative language is: C language
Interpretation type: The code is interpreted line by line, interpreted into binary, and then run (the code is interpreted line by line, and it is run while it is being interpreted)
Advantages: high development efficiency (there are many third-party library modules, which can be used directly), and can be cross-platform
Disadvantage: low execution efficiency
The python language is interpreted
5. Advantages and disadvantages of python:
Advantages of python:
1. Python is beautiful, clear and simple
2. Has a powerful third-party library, high development efficiency
3. It is a high-level language
Python disadvantages:
1. Compared with C language and Java language, the execution speed is slower
2. The code cannot be encrypted? ? ?
3. Threads cannot take advantage of the multi-CPU problem, which is the most criticized shortcoming of Python? ? ?
6. Classification of python
Python's writing and running process (type)
7. Write your first python program
Remember: enter python -V in cmd to open the python3 interpreter
Enter python2 -V in cmd to open the python2 interpreter
Write the first python file
print(’hello world‘)
python2 version: print 'content' or print('content')
python3 version: there is only one way to write - print('content')
run the first python file
Windows key + R to open the command line, enter python space file path and press Enter
Syntax error:
python2 version: the default encoding is ASCII
If you want to display Chinese in the python2 version, you need to add in the first line:
# -*- encoding: utf-8 -*-
python3 version: the default encoding is UTF-8
8. Definition of variables: store the middle of the calculation for subsequent code use
Rules for setting variables:
a. Must be any combination of letters, numbers, and underscores
b. Cannot start with a number
c. cannot be a keyword in python
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
d. The variable cannot be in Chinese
e. Variables cannot be too long
f. Variables are descriptive (see name definition) It is recommended to set variables with underscores
 
Exercise questions:
1. Right 2. Wrong 3. Right 4. Wrong 5. Wrong 6. Wrong
9. Constant: A quantity that has not changed. Variables that default to all uppercase are constants.
at the beginning of the file.
For example: ID number
10. Comments: help you understand other people's code and recall your own code
One-line comment:
#Commented content
Multi-line comments:
’‘’
Annotated content
’‘’
or
"""
Annotated content
"""
11. Basic data types:
int type: number, integer, used for calculation.
Remainder: % Quotient / Divide: //
str type: String. In python, whatever is quoted by nnn is a string
print('This is a string')//Single quotes
print("This is a string") // double quotes
//multiple quotes
(three single quotes or three double quotes)
String: Additive and Multiply
str+str: string concatenation
str*int: Multiplication of strings and integers, the result of the operation is that the string is repeated
bool型:true/false
Add a knowledge point: type() - view the data type
print('True',type('True'))//str
print(True,type(True))//boolean
Note: in Python 3 there is no longer type long, it's all int
12. Input user input (user interaction) new knowledge points
***Important: The input data types are all strings
#Assign the content entered by the user to the name variable,
name= input('Please enter the username')
# print the input content,
print(name)
practise:
name=input('what is your name?')
age=input('How old are you?')
hometown=input('Where is your hometown?')
print('Hello',name,'your are',age,'years old,you came from',hometown)
11.if selection judgment statement
The function of pass is: generally, when writing business logic, the content in else is easy to write, so you can write the business logic in else first, but pcharm will report an error if the content is not written in if, so use pass instead.
1. Separate if
if condition:
result
 
2.if else
name=input('Please enter your name')
if name=='wangye';
print("Old iron, no problem")
else;
print('There is something wrong and can be cured')
 
3.if elif ……
4.if elif ……else
5. Nesting
num1=input('Please enter a number')
if num=='3':
num1=input('Please enter a number')
if num2=='5':
print('This can be guessed correctly')
else:
print('Keep working hard')
12.while loop statement
while condition:
result
The running process of while:
terminate the loop
1. Change the condition:
Print numbers 1-100:
 
Print even numbers from 0-100:
 
2.break (can only be used in a loop)
See the break directly to end the loop
print 1+2+3+4+...+100
3.continue (can only be used in a loop)
When you see continue, end this cycle and continue to the next cycle.
The result of the operation is: 111 222 all the time
while ... else ..??? is used in what scenarios
Unlike other languages, else is generally only matched with if. In Python, there is also a while...else statement
The effect of the else after the while means that when the while loop is executed normally and is not interrupted by break in the middle, the statement after the else will be executed.
 
 
Exercise 2-4 has a very clear idea, and it is done by myself, indicating that the basic knowledge has been mastered
Exercise 1 and Exercise 5 are not clear
Exercise 1 was stuck at 7 and couldn't get rid of this loop. I forgot that 7 still had to participate in the loop, and printed 7 again. Exercise 5 is stuck on i auto-increment.
Remember, the code runs from top to bottom
Exercise 6 refers to the teacher's ideas and made it by myself
 
Question of the day:
1. The code cannot be encrypted? ? ?
2. Threads cannot take advantage of the multi-CPU problem, which is the most criticized shortcoming of Python? ? ?
3.Which ... else .. is used in what scenarios???
4. >>> What does this mean? ? ?
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325041270&siteId=291194637