第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

每當(dāng)任務(wù)(patternstart.finditer 中的匹配)返回 None 時(shí),如何創(chuàng)建操作?

每當(dāng)任務(wù)(patternstart.finditer 中的匹配)返回 None 時(shí),如何創(chuàng)建操作?

吃雞游戲 2023-06-27 13:48:44
每當(dāng)任務(wù)(對(duì)于patternStart.finditer(TestString) 中的匹配)未找到匹配項(xiàng)時(shí),我都會(huì)嘗試打?。ㄎ凑业狡ヅ漤?xiàng))。我一直堅(jiān)持這個(gè)沒有任何成功。任何意見,將不勝感激。字符串“jeke”故意不包含數(shù)字,因此找不到匹配項(xiàng)。TestString = 'jeke'patternStart = re.compile(r'\d')cnt = 0  # Initialize the counterwanted1 = [1]  # Defines the 1-based IDs of the matches you want to displaywanted2 = [2]  # Defines the 1-based IDs of the matches you want to displayfor match in patternStart.finditer(TestString):    cnt += 1    if cnt in wanted1:        out = match.group()    else:        print('match was not found')我已經(jīng)嘗試過了。if match.group() is None:    print('match was not found')if out is None:    print('match was not found')
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

您可以使用cnt來確定是否找到任何匹配項(xiàng):


for match in patternStart.finditer(TestString):

    cnt += 1

    if cnt in wanted1:

        out = match.group()

if cnt == 0:

    print('match was not found')

或者使用單獨(dú)的found_match變量:


found_match = False

for match in patternStart.finditer(TestString):

    found_match = True

    cnt += 1

    if cnt in wanted1:

        out = match.group()

if not found_match:

    print('match was not found')


查看完整回答
反對(duì) 回復(fù) 2023-06-27
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)