“C Too many seats , You will know ~ It's strange ~--- Kaikai doesn't cry ~ Kaikai is strong
”
I just finished writing the grammar set ,
Then make up some python Grammar point ~ Just open a third-party library ~~ This is more interesting
Even review the spelling of academic terms , It also makes sense .
About whether to add the semicolon at the end of the statement
Formatting tool
that will do ~ Python It's indented language ~ Be careful not to leave blank spaces tab
In fact, it is difficult to understand the literal quantity directly ~ I understand it the other way around
All can be named by themselves --- Function name , Class name , Variable names belong to identifiers identifier
The type of variable value ~ That is, the type of literal quantity ~
python There is no limit on the size of integers in , It can be an infinite integer
c = 123_456_789 # Underline at random
If the input content is not recognized, it will be reported invalid token
Other numbers in base ( I don't know how to use it )
Statements and expressions
Floating point numbers ( decimal ), stay Python All the decimals in are float type
When calculating floating-point numbers , You may get an imprecise result ( It's interesting )
a1 = 0.1
a2 = 0.2
print(a1+a2) # 0.30000000000000004
#### character string
Text message ~ String is used to represent ' Text information ' Of
Wrap in quotation marks
- You also need to use quotation marks inside double quotation marks. You need to use single quotation marks ---` The same quotation marks cannot be nested next to each other `
```python
a1 = ' Hoe standing grain gradually pawning a midday ,\
Sweat dripping under the grass ,\
Who knows what's on the plate ,\
Every grain is hard ,\
'
print(a1) # The result line
a2 = ''' Hoe standing grain gradually pawning a midday ,\
Sweat dripping under the grass ,\
Who knows what's on the plate ,\
Every grain is hard ,\
'''
print(a2) # No branches
a3 = ''' Hoe standing grain gradually pawning a midday ,
Sweat dripping under the grass ,
Who knows what's on the plate ,
Every grain is hard ,
'''
print(a3) # branch
From the above, we can find , This backslash acts like a " Soft wrap "
Just tell the interpreter , The following line breaks should not be regarded as line breaks / Connect content
“It's actually called Line continuation operator ~ It is also a kind of
”Escape character
“There are some inconvenient web pages ~ Because it is not necessarily a single web page ~ For example, format retention . Need to keep writing escape characters
C In this respect, it is even more outrageous
”
Write an interesting \u0040 You can display a @ Symbol
\u After that unicode code 4 position
“No dice ... The editor doesn't produce results You dare to use it directly in the browser ?
”
intro = ' Hello '
name = 'Shinkai'
# The same string type can be added
print(intro + name) # Hello Shinkai
# The following expression is used in python Not often
print(intro + name + "!!!!!") # Hello Shinkai!!!!!
# It is usually written like this
print(intro+name, "!!!!!") # Hello Shinkai !!!!!
str = 'hello %s' % ' The Monkey King ' # %s yes string Abbreviation
print(str) # hello The Monkey King
str1 = 'hello %s Hello %s' % ('monkey', ' The Monkey King ')
print(str1) # hello monkey Hello The Monkey King
str2 = 'hello %3s' % 'ab' # Minimum string length 3
print(str2) # hello ab
str3 = 'hello %3.5s' % 'abcdef' # The string length is 3-5
print(str3) # hello abcde
%f It's a floating-point placeholder
%d Is an integer placeholder , Just round off the decimal part
“Just don't use so fine ~ I just know when I study ~
”
res = 'res'
print('res = %s' % res) # res = res
intro = 'hello'
name = 'Shinkai'
res = f'{intro} {name}'
print(res) # hello Shinkai
“I want to play with the flowers. I read the newspaper wrong. OK .. Don't simulate everything
”
To summarize the string splicing methods 4 Kind of ( There are actually two kinds )
“python Unique , character string *n Will repeat the string n Return times
”
name = 'Shinkai' * 2
print('hello ' + name) # hello ShinkaiShinkai
print('hello', name)
print('hello %s ' % name)
print(f'hello {name} ')
logic
Boolean values are actually integers , True yes 1, False yes 0
print(1 + True) # 2
print(1 + False) # 1
print(1 * False) # 0
None Does not exist Don't follow null It doesn't exist null Type but with None type
The contents mentioned so far above, There are strings , The number , Null value
The value contains : integer ( Contains Boolean ), floating-point , The plural
str = '123'
num = 123
print(str) # 123
print(num) # 123
You can see Different types of content It's all printed out 123 I don't know the type ~
“actually pycharm When the pointer is placed on the variable, it shows ~
”
print(type(num)) # <class 'str'>
print(type(str)) # <class 'int'>
All types of checks
# Type checking
print(type('123')) # <class 'str'>
print(type(123)) # <class 'int'>
print(type(123.123)) # <class 'float'>
print(type(True)) # <class 'bool'>
print(type(None)) # <class 'NoneType'>
python It's an object-oriented language ~
“To put it bluntly, today's are all object-oriented , Object - oriented is called object - oriented as long as its syntax contains declarative expressions .....
”
“There are many things to learn again ~ This is the content of the operating system
Scheduling algorithm ~ Although we don't have to ~ But having one doesn't make much difference
This difference has a static data area Static variables are placed here .
”
Don't write here ~ There's too much content ....
Each object will have one id, type, value
“We downloaded the official version of python, That is, there is no prefix python Interpreter ~ So is Cpython, Cpython Of id Is the memory address of variable storage
”
# Object structure
name = 'Shinkai'
print(id(name)) # 4313468016, 4443786352
print(type(name)) # <class 'str'>
print(name) # Shinkai
Objects don't actually exist directly in variables , What is actually stored is the address of the object in memory
test = 123
test2 = test
test3 = 123
print(test == test2) # True
print(test == test3) # True
# It's the same way to write
test = {"key": "value"}
test2 = test
test3 = {"key": "value"}
print(test == test2) # True
print(test == test3) # True
Python It's a strong type , It cannot affect the declared variables , And can not be implicitly converted ~ But you can assign the content to the original variable after forced conversion ~
Variables can be assigned infinitely ~
“To explain, for example int(a), Actually a Change the type of int Then copy the rest , Then give this address to a.
”
similar int(), But it's in decimal form
Ture->'True'
False->'False'
123->'123'
...
a=True
0,None,'' Empty strings are False
# + The addition operator ( If it's an addition between two strings , String splicing will be performed )
# - Subtraction operators
# * Multiplication operators ( If you multiply a string by a number , Then the string will be copied , Repeat the string a specified number of times )
# / Division operator , The result will always return a floating point type
# // to be divisible by , Only the whole digits after calculation will be reserved
# ** Power operation
# % Modulo complementary operation The result is the remainder
= Simply assign the right value to the left
print('2'>'11') # true
In fact, the string comparison is unicode code ~ Everyone 's unicode. The first greater than is true
“js equally
”
It can be inferred that
'a'>'b' # false
'ab' > 'b' # false
“It's useless but interesting .
”
Logic is not not
Logic and and
Logic or or
False and print(a) # No printing
True and print(a) # Print
False or print(a) # Print
True or print(a) # No printing
Convert each value to a Boolean operation
res = 1 and 2 # The first is true, Go back to the second
res = 1 and 0
res = 0 and 1 # The first is false A short circuit Go straight back to false
or equally ~
grammar : sentence 1 if expression else sentence 2
print('1') if True else print('2')
It's usually used this way
max = a if a > b else b
Namely max yes ab A medium large number
I suggest adding brackets first
Look at the priority table , Don't pay any attention to him Hate him , If you don't understand it diss He
Code block
a = 2
if a == 1:
print('1')
print('2')
print('3') # 3
input() Function can temporarily prevent the program from ending ~ End after entering random characters ~
if- elif -else
# # Even and odd numbers
# num = int(input(' Enter any number '))
# print(' even numbers ' if num % 2 == 0 else ' Odd number ')
# # Leap year judgment
# year = int(input(' Enter any year '))
# print(' Leap year ' if ((year % 100 != 0 and year % 4 == 0) or (year % 100 == 0))else ' Non leap year ')
# # A dog is a man's age
# dog_age = int(input(' Please enter your dog's age '))
# if dog_age <= 0:
# print(' Who are you kidding ')
# elif dog_age <= 2:
# person_age = dog_age * 10.5
# print(f' A dog is as old as a man {person_age}')
# else:
# person_age = (dog_age - 2) * 4 + 21
# print(f' A dog is as old as a man {person_age}')
# According to the score , Give a reward
# score = int(input(' Please enter your score '))
# if score == 100:
# print('niubi666')
# elif 80 <= score <= 99:
# print(' ok ')
# elif 60 <= score <= 79:
# print(' The butt blossoms ')
# else:
# print('no Reward ')
# print(bool(0))
# print(bool('0'))
# Whether to marry or not ~
# question1 = bool(input('1 be for the purpose of , If it is not filled in, it means No , A house ?'))
# question2 = bool(input('1 be for the purpose of , If it is not filled in, it means No , A car ?'))
# question3 = bool(input('1 be for the purpose of , If it is not filled in, it means No , Handsome ?'))
# if question1 or question2 or question3:
# if question1 and question2 and question3:
# print(' Married married ')
# else:
# print(' You can live a little ')
# else:
# print(' You are here to make fun of me ')
# a1 = ' Hoe standing grain gradually pawning a midday ,\
# Sweat dripping under the grass ,\
# Who knows what's on the plate ,\
# Every grain is hard ,\
# '
# print(a1) # The result line
# a2 = ''' Hoe standing grain gradually pawning a midday ,\
# Sweat dripping under the grass ,\
# Who knows what's on the plate ,\
# Every grain is hard ,\
# '''
# print(a2) # No branches
# a3 = ''' Hoe standing grain gradually pawning a midday ,
# Sweat dripping under the grass ,
# Who knows what's on the plate ,
# Every grain is hard ,
# '''
# print(a3) # branch
# intro = ' Hello '
# name = 'Shinkai'
# # The same string type can be added
# print(intro + name) # Hello Shinkai
# # The following expression is used in python Not often
# print(intro + name + "!!!!!") # Hello Shinkai!!!!!
# # It is usually written like this
# print(intro+name, "!!!!!") # Hello Shinkai !!!!!
# str = 'hello %s' % ' The Monkey King ' # %s yes string Abbreviation
# print(str) # hello The Monkey King
# str1 = 'hello %s Hello %s' % ('monkey', ' The Monkey King ')
# print(str1) # hello monkey Hello The Monkey King
# str2 = 'hello %3s' % 'ab' # Minimum string length 3
# print(str2) # hello ab
# str3 = 'hello %3.5s' % 'abcdef' # The string length is 3-5
# print(str3) # hello abcde
# res = 'res'
# print('res = %s' % res) # res = res
# # A better way to write
# intro = 'hello'
# name = 'Shinkai'
# res = f'{intro} {name}'
# print(res) # hello Shinkai
# assignment
# name = 'Shinkai' * 2
# print('hello ' + name) # hello ShinkaiShinkai
# print('hello', name)
# print('hello %s ' % name)
# print(f'hello {name} ')
# print(1 + True) # 2
# print(1 + False) # 1
# print(1 * False) # 0
# str = '123'
# num = 123
# print(str) # 123
# print(num) # 123
# print(type(num)) # <class 'str'>
# print(type(str)) # <class 'int'>
# # Type checking
# print(type('123')) # <class 'str'>
# print(type(123)) # <class 'int'>
# print(type(123.123)) # <class 'float'>
# print(type(True)) # <class 'bool'>
# print(type(None)) # <class 'NoneType'>
# # Object structure
# name = 'Shinkai'
# print(id(name)) # 4313468016, 4443786352
# print(type(name)) # <class 'str'>
# print(name) # Shinkai
# test = {"key": "value"}
# test2 = test
# test3 = {"key": "value"}
# print(test == test2) # True
# print(test == test3) # True
# # Type conversion
# a = True
# a = int(a)
# print(a)
# a = 2**2
# print(a)
# obj1 = {'a': 123}
# obj2 = {'a': 123}
# print(obj1 is obj2)
# a = 0
# a = not a
# print(a)
# a = 0
# False and print(a) # No printing
# True and print(a) # Print
# False or print(a) # Print
# True or print(a) # No printing
# print('1') if True else print('2')
# if 1 == 1:
# print('1')
# print('1')
# a = 2
# if a == 1:
# print('1')
# print('2')
# print('3')
# a = input(' Please enter 1-100 A number ')
# if a == '123':
# print(' Correct answer ')
# else:
# print(' Wrong answer , Your answer is ', a)
# age = int(input(' Please enter your age :'))
# if age > 18:
# print(' You are an adult ')
# elif age > 10:
# print(' You went to primary school ')
# elif age <= 3:
# print(' You are still a child ')
# else:
# print(' Strange age ')
# # Even and odd numbers
# num = int(input(' Enter any number '))
# print(' even numbers ' if num % 2 == 0 else ' Odd number ')
# # Leap year judgment
# year = int(input(' Enter any year '))
# print(' Leap year ' if ((year % 100 != 0 and year % 4 == 0) or (year % 100 == 0))else ' Non leap year ')
# dog_age = int(input(' Please enter your dog's age '))
# if dog_age <= 0:
# print(' Who are you kidding ')
# elif dog_age <= 2:
# person_age = dog_age * 10.5
# print(f' A dog is as old as a man {person_age}')
# else:
# person_age = (dog_age - 2) * 4 + 21
# print(f' A dog is as old as a man {person_age}')
# score = int(input(' Please enter your score '))
# if score == 100:
# print('niubi666')
# elif 80 <= score <= 99:
# print(' ok ')
# elif 60 <= score <= 79:
# print(' The butt blossoms ')
# else:
# print('no Reward ')
# print(bool(0))
# print(bool('0'))
# question1 = bool(input('1 be for the purpose of , If it is not filled in, it means No , A house ?'))
# question2 = bool(input('1 be for the purpose of , If it is not filled in, it means No , A car ?'))
# question3 = bool(input('1 be for the purpose of , If it is not filled in, it means No , Handsome ?'))
# if question1 or question2 or question3:
# if question1 and question2 and question3:
# print(' Married married ')
# else:
# print(' You can live a little ')
# else:
# print(' You are here to make fun of me ')
command + / notes
shift+ enter The cursor jumps to the beginning of the next line
option+command + L formatting code
shift+command+ Up and down All contents of the current line can be moved up and down
“Many differences ....js Give up everything you can
js Not at all ' Static resource area ' Or static resources are stored in the stack . See, no one asked
”
“js Can't print Memory address , The trouble can only be judged by double and third class
js On the bottom api Many have not been thrown out
”
python There is no third class
Don't compare addresses ~ After all, you can see the memory address ~
js The object content is the same , But the memory addresses are different. The comparison will show false
js in == Two objects actually compare memory addresses ~so It can't be the same unless it points to the same
python use is and is not To compare The memory address is id similar js===
It can be used to compare whether it is the same object
python Do not distinguish between reference data types and basic data types , The distinction is between variable and immutable data types
python Illegal string to numeric value , Will report a mistake js There is no error report NaN type ~
python One more integral division operation // And multiply by the string ~
python and js Short circuit operation is also available
python It can be compared in a chain 1<score<100
js Of '0' Turn Boolean yes false js Implicit conversions tend to be numeric '0' by 0 0 yes false
python Of '0' Turn Boolean yes true.