url: python Operator collation _Y-shark The blog of -CSDN Blog
Hold down ctrl Then click on the title
pdf edition ( Net disk access )
link :https://pan.baidu.com/s/1oS8105PD9YC6NIW2J10ZnA Extraction code :awda
Homework 1:
Judge "amy" Whether in ["bob","tony","Lisa","Steven"] Inside , If it is, output 'amy In the logical family ', Otherwise output 'amy be not in ... So sad '
analysis :
The member operator is used
Code :( Two kinds of )
list=["bob","tony","Lisa","Steven"] if "amy" in list: print("amy In the logical family ") else: print("amy be not in ... So sad ")
The ternary operator is used !
Homework 2:
'ax'<'xa' by True still False?
Why? ?
analysis :True
The comparison between strings is based on ASCCII Compare the size of
ax Of ASCCII Code is 97,120
xa yes ASCCII Code is 120,97
then ax and xa Compare one by one 97<120, therefore ax<xa
Code :
print("ax"<"xa")
Homework 3:
If the following procedure is entered 666 Which statement to execute ? Why? ?
temp=input(' Please enter :')
if temp == 'Yes' or 'yes':
print('if Yes !')
else:
print('else Yes !')
analysis :
perform "if Yes !"
== and or Than to carry out ==
or:1、 really or really = really 2、 really or false = really 3、 false or false = false
Code :
temp=input(" Please enter :")
if temp=="Yes" or "yes":
print("if Yes !")
else:
print("else Yes !")
Homework 4:
is And == The difference between ?
analysis :
There's a difference
is Is an identity operator ,== Is a comparison operator , They are all used for comparison , But the comparison values are different ,is Compare memory addresses ,== Is used to compare values
Homework 5:
User input a,b
When a And b Not for 0 Output when a And b Do business ; Otherwise output a And b The product of the
analysis :
Code :
a=int(input(" Please enter a Corresponding number :")) b=int(input(" Please enter b Corresponding number :")) if a != 0 and b !=0: print(a//b) else: print(a*b)
a and b Not for 0 when :
a and b One side is zero or both :
Homework 6:
Question based 5, Use the ternary operator to output a,b A larger number
analysis :
Code :
a=int(input(" Please enter a Corresponding number :")) b=int(input(" Please enter b Corresponding number :"))