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

3.python process judgment

編輯:Python

if Judge

Routine usage

 Grammar memory methods
if+ Space + Conditions + The colon
tab Indent code body
tab Indent code body
tab Indent code body

Three mesh operation

 Results satisfying the conditions if Conditions else The result of not meeting the conditions

More branches

if Conditions 1:
code1
elif Conditions 2:
code1
elif Conditions 3:
code1
else:
code1

Logical operators

principle

(1) not The highest priority , It is to reverse the result of the following condition , therefore not It is inseparable from the following conditions
(2) If all of the statements use and Connect , Or all of them or Connect , Then it can be calculated from left to right
(3) If there is both and Also have or, So let's start with brackets and The left and right conditions of , And then we do the calculation

and And ( priority 3)

 Connect the left and right conditions , Only when the two conditions hold at the same time will the final result be True

or or ( priority 2)

 Connect the left and right conditions , If one condition holds, the final result will be True

not Not ( priority 1)

 Take the opposite by true

for loop

for Variable name in Data to cycle :
for Loop through Dictionary
namess = {'name1':'dahai','name2':'xialuo','name3':'xishi'}

Default traversal key value

for i in namess:
print(i)

The second kind of traversal key value

for i in namess.keys():
print(i)

Traverse value value

for i in namess:
print(namess[i])
print(i)

Direct fetch traversal value value

for i in namess.values():
print(i)

Traversal key value pairs

for i in namess.items():
# take key
print(i[0])
# take value
print(i[1])

for Loop through the list

for a in names:
print(a)

range(0 start ,10 End ,2 step )

 It's an iterator range and list Equivalent , however range Smaller memory footprint .

List to heavy

list1=['aaa','bbb','ccc']
list2 = ['ccc']
for i in list1:
if i in list2:
print(' Already there. ')
else:
list2.append(i)

enumeration enumerate

goods_list=[
['coffee',30],
['chicken',20],
['iphone',10000],
['car',100000],
['building',200000]
]
for i,item in enumerate(goods_list):
print(i,item)

while loop

while Conditions :

while Conditions :
code1
code2
code3

while True:

while True:
print('111')
print('222')
**continue Skip this cycle **
**break Represents the end of the loop **

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