程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python operator operation and parsing

編輯:Python

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 :"))

print(a if a>b else b )

When a>b when                                                                    When b>a when :

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved