日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯網營銷解決方案
Python程序:查找字符串中的字符的所有出現

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

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

寫一個 Python 程序,用一個實際例子找出字符串中字符的所有出現。

Python 程序查找字符串中的字符的所有出現示例 1

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

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 程序返回字符串中的字符的所有出現示例 2

這個 Python 顯示字符串程序中字符的所有出現與上面相同。然而,我們只是將循環(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 中所有字符出現在一個字符串中輸出

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

顯示字符串中的字符總出現次數的 Python 程序示例 3

這個 Python 查找字符串中的字符的所有出現與第一個示例相同。但是,在這個 python 程序中,我們使用了函數的概念來分離 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)


分享名稱:Python程序:查找字符串中的字符的所有出現
地址分享:http://m.5511xx.com/article/dhijccg.html