当前位置:网站首页>Day3 data types and operators summary and job
Day3 data types and operators summary and job
2022-06-25 23:23:00 【tw886】
Today's summary
One 、 Variable
1、 Variable : It is a kind of container specially used to store data ( Variables are used to hold data , After saving the data , Using variables
Is to use the data stored in the variable )
grammar :
Variable name = data
explain :
1) Variable name — Named by the programmer himself
requirement :a. Is an identifier.
b. It can't be a keyword
standard :a. Know what you know ( When you see the variable name, you know what data is stored in the variable )
b. Do not use the system function name (print、input、type)、 Class name (int、float、…) And the module name c. The letters are all lowercase ,
Multiple words are separated by underscores
2)= - Assignment symbol ; Fixed writing
3) data - It can be any expression with a result , such as : A specific data 、 Calculation results 、 Variables that have been assigned 、 function
Call expressions, etc
2、 Define multiple variables at the same time
1) Define multiple variables at the same time and assign the same value : Variable name 1 = Variable name 2 = Variable name 3 = … = data
a1 = a2 = a3 = 100
2) Define multiple variables at the same time and assign different values : Variable name 1, Variable name 2, Variable name 3, … = data 1, data 2, data 3, …
The number of the preceding variables must be consistent with the number of the following data
b1, b2 = 10, 20
3、python The principle of defining variables and reassigning variables
python The variable is defined by applying for memory first , The size of the memory application depends on the size of the data to be saved ;
When reassigning , Will reapply for new memory , The size of the new memory depends on the size of the new data .
id( Variable ) - Gets the address of the data in the variable
Two 、 Mathematical operators
1、 Add, subtract, multiply and divide
python The addition, subtraction, multiplication and division in is the same as in mathematics
Be careful :/ The result of the operation must be float; +、-、* The type of operation result depends on whether there are floating-point numbers in the operation object
2、 Remainder ( modulus ) - %
Remainder is the remainder in mathematics
The rules : x % y – seek x Divide y The remainder of
Application scenarios 1: Judge whether there is an integer division relationship between two numbers - Judge whether the remainder of two numbers is 0
Application scenarios 2: Take the lower digits - Yes 10 perhaps 10 Of N Secondary surplus
3、 to be divisible by - //
function : Seeking quotient , Quotient rounding off
Application scenarios 1: Get the quotient of an integer if it can be divided by an integer
Application scenarios 2: Remove the lower digits of an integer - to be divisible by 10 perhaps 10 Of N The next power
4、 Power operation -**
The rules : x ** y - seek x Of y Power
3、 ... and 、 Comparison operator
Comparison operator :>( Greater than )、<( Less than )、==( be equal to )、>=( Greater than or equal to )、<=( Less than or equal to )、!=( It's not equal to )
Be careful 1: The result of all comparison operators is Boolean
Be careful 2:python The comparison operators in can be concatenated to represent the range like mathematics
Four 、 Logical operators
1、 Logic and - and
Application scenarios : Equivalent to... In life ’ also ’, It is used to connect two conditions that are true at the same time
Operator rule : Conditions 1 and Conditions 2 - All two are True The result is True, As long as one is False The result is False
True and True - True
True and False - False
False and True - False
False and False - False
2、 Logic or - or
Application scenarios : Equivalent to... In life ’ perhaps ’; If two or more conditions are required, as long as one condition is satisfied , So take these
Conditional use or Connect
Operational rules : Conditions 1 or Conditions 2 - All two are False The result is False, As long as one is True The result is True
True or True - True
True or False - True
False or True - True
False or False - False
3、 Logic is not - not
Application scenarios : Deny a condition ; If a condition is written forward, the situation is very complicated , The reverse is simple , Then we will
Condition reverse write plus not
Operational rules :not Conditions - Negate the specified condition
not True - False
not False - True
5、 ... and 、 Assignment operator
Assignment operator :=、+=、-=、*=、/=、%=、//=、**=
Conclusion : The function of all assignment operators is to store data in variables
1、=
Variable name = data - take = The data on the right is assigned to the variable on the left ( Variable names can be defined , It can also be undefined )
2、 +=
Variable name += data - Take out the data saved in the variable and add it with the following data , Reassign the result of the operation to the variable
( Variable names must be defined )
3、 Operator precedence
Mathematical operators > Comparison operator > Logical operators > Assignment operator ( The minimum )
** > *、/、%、// > +、-
If there are brackets, count them first
day3 Data types and Operator jobs
choice question
print(100 - 25 * 3 % 4)What should be output ? (B)A. 1B. 97C. 25D. 0Which of the following statements is wrong (D).
A. Except for dictionary types , All standard objects can be used for Boolean testingB. The Boolean value of an empty string is FalseC. The Boolean value of an empty list object is FalseD. The value is 0 The Boolean value of any numeric object of is FalsePython Unsupported data types are (A).
A. charB. intC. floatD. list( multi-select )n = 6784, You can get 7 The way to do this is (CD).
A. n / 1000 % 100B. n % 1000 / 100C. n // 100 % 10D. n // 10 % 100 // 10Run the following program , When entering... From the keyboard 12, The result of the operation is (A).
x = (input()) print(type(x))A.
<class 'str'>B.
<class 'int'>C.
errorD.
class 'dict'The operation result of the following expression is ( D ) .
a = 100 b = False print(a * b > -1)A.
FalseB.
1C.
0D.
True
Completion
stay Python The empty type is (None).
The function name to view the type of data in the variable is (type).
It is known that
x = 3 == 3, After execution , Variable x The value of is (True).It is known that
x = 3, Then execute the statementx += 6after ,x The value of is (9).expression
3 ** 2The value of is (9), expression3 * 2The value of is (6), expression4 ** 0.5The value of is (2).
Programming questions
Write to determine whether a number can be simultaneously 3 and 7 Divisible conditional statement , And print the corresponding results .
for example : Input 21 Print True, Input 9 Print False. num = int(input(' Please enter a number :')) print(num % 3 == 0 and num % 7 == 0)Write to determine whether a number can be 3 perhaps 7 to be divisible by , But not both 3 perhaps 7 Divisible conditional statement , And print the corresponding results .
for example : Input 14 Print True, Input 4 Print False, Input 21 Print False. num = int(input(' Please enter a number :')) print((num % 3 == 0 or num % 7 == 0) and (not(num % 3 == 0 and num % 7 == 0) ))Enter year , Write code to judge whether the entered year is a leap year , And print the corresponding results .( It's a leap year condition : Can be 4 Divisible but not by 100 Divisible or capable of being divisible by 400 Divisible year )
for example : Input 2020 Print True, Input 2011 Print False year = int(input(' Please enter the year :')) print((year % 4 == 0 and year % 100 != 0) or (year % 400 == 0))Suppose today's class time is 15678 second , Programming to calculate the class time today is how many hours , How many minutes? , How many seconds ; With ‘XX when XX branch XX second ’ It's expressed in a different way .
for example : Time 67 second —> 0 when 1 branch 7 second time = int(input(' Please enter the time :')) hour = time // 3600 minute = time % 3600 // 60 second = time % 3600 % 60 print(hour,' when ',minute,' branch ',second,' second ',sep = '')Define two variables to save a person's height and weight , Programming to determine whether the person's body is normal !
The formula :
weight (kg)/ height (m) The square value ofstay 18.5 ~ 24.9 It's normal .for example : Enter the weight : 55, Enter the height :1.55, Output : True height = float(input(' Please enter height :')) weight = int(input(' Please enter the weight :')) index = weight / (height ** 2) print( 18.5 <= index <= 24.9)
Short answer
Python What are the built-in data types ?
integer (int)、 floating-point (float)、 Boolean (bool)、 Null value (None)、 Character (str).
Write your thoughts about today ⽇ Where there are questions in the teaching content of the day ⽅ Fang ( Or knowledge points that feel difficult ).
nothing
边栏推荐
猜你喜欢

Pit resolution encountered using East OCR (compile LAMS)

Oracle - getting started

字符串变形(字符串大小写切换和变现)

1281_ FreeRTOS_ Implementation analysis of vtaskdelayuntil

Actual combat: how to quickly change font color in typera (blog sharing - perfect) -2022.6.25 (solved)

22 years of a doctor in Huawei

UE4_UE5结合offline voice recognition插件做语音识别功能

The Ping class of unity uses

Live800 online customer service system: do business across time and space, starting from each interaction

如何用jmeter做接口测试
随机推荐
Oracle - 基本入门
UE4\UE5 蓝图节点Delay与Retriggerable Delay的使用与区别
判断预约时间是否已经过期
Multithreaded learning 2- call control
多模态数据也能进行MAE?伯克利&谷歌提出M3AE,在图像和文本数据上进行MAE!最优掩蔽率可达75%,显著高于BERT的15%...
As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)
Kubernetes cluster construction of multiple ECS
Pit resolution encountered using East OCR (compile LAMS)
万亿热钱砸向太空经济,真的是一门好生意?
Mysql database index
LM小型可编程控制器软件(基于CoDeSys)笔记十七:pto脉冲功能块
小程序绘制一个简单的饼图
User interaction scanner usage Advanced Edition example
电路模块分析练习5(电源)
Es7/es9 -- new features and regularities
pdm的皮毛
建立自己的网站(15)
关闭MongoDB一些服务需要注意的地方(以及开启的相关命令)
小程序-视图与逻辑
Multi modal data can also be Mae? Berkeley & Google proposed m3ae to conduct Mae on image and text data! The optimal masking rate can reach 75%, significantly higher than 15% of Bert