日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:查找字符串中的字符的所有出現(xiàn)

創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站設(shè)計(jì)、做網(wǎng)站與策劃設(shè)計(jì),克拉瑪依網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:克拉瑪依等地區(qū)??死斠雷鼍W(wǎng)站價(jià)格咨詢:18980820575

寫一個(gè) Python 程序,用一個(gè)實(shí)際例子找出字符串中字符的所有出現(xiàn)。

Python 程序查找字符串中的字符的所有出現(xiàn)示例 1

這個(gè) python 程序允許用戶輸入字符串和字符。這里,我們使用 For 循環(huán)來迭代字符串中的每個(gè)字符。在 Python For Loop 中,我們使用 If 語句來檢查 str1 字符串中的任何字符是否等于字符 ch。如果為真,則我將值打印為輸出。記住,I 是一個(gè)索引位置(從 0 開始)。

# Python Program to find Occurrence of a Character in a String

str1 = input("Please enter your own String : ")
ch = input("Please enter your own Character : ")

for i in range(len(str1)):
    if(str1[i] == ch ):
        print(ch, " is Found at Position " , i + 1)

Python 字符串輸出中字符的所有出現(xiàn)

Please enter your own String : tutorial gateway
Please enter your own Character : t
t  is Found at Position  1
t  is Found at Position  3
t  is Found at Position  12

Python 程序返回字符串中的字符的所有出現(xiàn)示例 2

這個(gè) Python 顯示字符串程序中字符的所有出現(xiàn)與上面相同。然而,我們只是將循環(huán)的替換為循環(huán)的。

# Python Program to find Occurrence of a Character in a String

str1 = input("Please enter your own String : ")
ch = input("Please enter your own Character : ")
i = 0

while(i < len(str1)):
    if(str1[i] == ch ):
        print(ch, " is Found at Position " , i + 1)
    i = i + 1

Python 中所有字符出現(xiàn)在一個(gè)字符串中輸出

Please enter your own String : hello world
Please enter your own Character : l
l  is Found at Position  3
l  is Found at Position  4
l  is Found at Position  10

顯示字符串中的字符總出現(xiàn)次數(shù)的 Python 程序示例 3

這個(gè) Python 查找字符串中的字符的所有出現(xiàn)與第一個(gè)示例相同。但是,在這個(gè) python 程序中,我們使用了函數(shù)的概念來分離 Python 邏輯。

# Python Program to find Occurrence of a Character in a String

def all_Occurrence(ch, str1):
    for i in range(len(str1)):
        if(str1[i] == ch ):
            print(ch, " is Found at Position " , i + 1)

string = input("Please enter your own String : ")
char = input("Please enter your own Character : ")
all_Occurrence(char, string)


網(wǎng)頁標(biāo)題:Python程序:查找字符串中的字符的所有出現(xiàn)
瀏覽地址:http://www.dlmjj.cn/article/dhijccg.html