1、python Is a programming language
Programming language is a language that people and computers can communicate with
people ---------- programing language --------- Computer
2、 Programming is :
① Think clearly about the steps of what people are going to do
② Find a language that the computer can understand 1 Translate it down
Bank President ------------------------- Counter users
Receive the user name entered by the user
Receive the password entered by the user
Judge that the user name entered is equal to the correct user And the password entered is equal to the correct password
Tell the user that the login is successful
otherwise
Tell the user that login failed
people ----------------- Computer
3、 A program is a series of code files
4、 Programming is to make computers work according to human logic , Instead of manpower
5、 Three core hardware
cpu
Memory
Hard disk
The program starts with the hard disk , And then read it into memory
6、 Complete computer architecture diagram
Programs written in interpretive languages Programs written in interpretive languages
command command
python Interpreter shell Interpreter cmd Interpreter Applications
system interface
kernel
computer hardware
# The position of the note 1
print("hello world") # Note location 2( The first two squares of the well number , The latter )
# ctrl+? Batch annotation
# print(1)
# print(2)
# print(3)
# ctrl+d Quickly copy the current line and paste it to the next line
# shift+enter Fast line feed
1、 Defining variables
age = 18
level = 10
name = "Makka Pakka"
2、 Reference variables
print(age)
Add : Be sure to define before quoting
There are two ways to report an error
① Grammar mistakes ( None of the lines run , Direct error )
print(111)
print(222)
print(333
print(444)
② Logic error ( Run to the wrong line and report an error )
print(111)
print(222)
ess
print(444)
"ess" # Quotation marks are a kind of value , The variable name without quotation marks
3、 The three components of a variable
3.1 Variable name : To access the value of a variable
3.2 Assignment symbol : Bind the memory address of the value to the variable name
3.3 A variable's value : Record the state of things , Instant data 4、 Variable names
The big premise : See the name and know the meaning
age = 18
level = 10
On the premise of knowing the meaning by seeing the name :
① Variable names are made up of alphanumeric underscores
② Cannot start with a number
③ Out of commission python Keywords of language
'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'
Naming style
Ⅰ All lowercase and underline
age_of_ccc = 18
Ⅱ Hump body
AgeOfCcc = 18
5、 Two characteristics of variable values
id-> ID card of variable value , The response is the memory address
type-> The type of variable value
x=10
y="ccc"
print(id(x)) # 140707833976768
print(type(y)) # <class 'str'>
id The same represents the same memory address , That is to say, it points to the same memory space , The value must be the same
Have the same value ( namely == establish ),id Not necessarily the same , In other words, different memory spaces can hold the same value
is The judgment is id Are they the same?
== It's about whether the values are equal
6、 Constant
python There is no constant , But you can use all uppercase variable names to represent constants
AGE_OF_OLDBOY = 73
AGE_OF_OLDBOY = 74
Define the constant again , The value of the constant changes , So there's no constant
7、 Garbage collection mechanism
7.1 Reference count
7.2 A vulnerability in the reference counting mechanism : Circular reference -> Memory leak : Mark - clear
7.3 The efficiency of the reference counting mechanism : Generational recycling
x = 18
y = x
y = 20
del x