2017-04-18 70 views
-4

任何人都可以告訴我如何跳過一個函數調用,如果一個特定的條件爲真,例如if r[3]=='Device':如果這個條件是真的,那麼下一個函數調用必須跳過,如果這個條件不是真的,那麼必須執行下一個函數調用。代碼會像如何根據if語句的true或false跳過一個函數調用?

第一功能:

def sei1(r): 
     if r[4]=='Device': 
      print(r[1],r[2],r[3]) 
      if r[7]=='Device': 
       print(r[5],r[6]) 
      if r[7]=='list': 
       print(r[5],r[6]) 
      if r[8]=='Device': 
       print(r[5],r[6],r[7]) 
      if r[8]=='list': 
       print(r[5],r[6],r[7]) 
     def se(r): 
     if r[5]=='Device': 
      print(r[1],r[2],r[3],r[4]) 
      if r[8]=='Device': 
       print(r[6],r[7]) 
      if r[7]=='list': 
       print(r[6],r[7]) 
      if r[8]=='Device': 
       print(r[6],r[7],r[8]) 
      if r[8]=='list': 
       print(r[6],r[7],r[8]) 
     sei1(r) 
     se(r) 

這是兩個函數和我需要的是如果r [4] ==「設備」爲真,那麼下一個函數調用SE(R)不得執行。

我是新的python每個建議表示讚賞。 謝謝

+0

使用'='來檢查,如果事情不等於! – meyer9

+0

請分享一些代碼 –

+0

'if r [3] =='Device': pass' –

回答

4

你需要簡單的檢查如下:

if r[3]!='Device': # function_call is a function which will only execute when r[3] is not equal to 'Device' 
    function_call() 

OR

if r[3]=='Device': 
    pass 
else: 
    function_call() 
1

By skip你是不是在執行它?在那種情況下,好的醇'簡單,如果應該工作正常?

if r[3] != 'Device': 
    func1() 
    print('function is executed!') 
else: 
    print('function is NOT executed!') 
+0

yes by skip i mean mean not executed –

0
if r[3]=='Device': 
    pass 
else: 
    function()