A. python字典,如何查找值中包含指定字元串的鍵

1、說明python中檢測字典的鍵中是否含有某串字元,便利字典鍵值,再判斷字元串是否在鍵值中即可。2、示例代碼:# 定義一個字典dic = {'1984/1/2': 123, '1984/1/3': 0, '1985/1/1': 156}# 遍歷字典鍵中是否包含1984for key in dic: if '1984' in key: print('鍵值中包含字元串"1984"') # 或者需要的其它操作 else: print('鍵值中不包含字元串"1984"')3、執行結果:鍵值中包含字元串"1984"鍵值中不包含字元串"1984"鍵值中包含字元串"1984"

4、其它說明:python使用for in直接操作字典就是遍歷字典的鍵值,python使用in操作來判斷字元串中是否包含子串最方便,要優於使用字元串的函數index或者find。

index函數在找不到子串時會報錯,find函數會返回-1。

B. 如何在Python字元串列表中查找出指定字元所在字元串

re.findall('\w*{}\w*'.format(c),','.join(l))

Python 3.5.2 (default, Dec 7 2016, 23:38:49)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux

Type "help", "right", "credits" or "license" for more information.

>>> import re

>>> l=['sfdsd','ddff']

>>> c='s'

>>> re.findall('\w*{}\w*'.format(c),','.join(l))

['sfdsd']

C. python 查找字元串中是否包含指定非連續字元

用一個庫函數,就是sscanf。它是從字元串中讀取數據,如果讀取的數據等於你的b中的每個元素。
Python(英語發音:/ˈpaɪθən/), 是一種面向對象、解釋型計算機程序設計語言,由Guido van Rossum於1989年底發明,第一個公開發行版發行於1991年,Python 源代碼同樣遵循 GPL(GNU General Public License)協議。Python語法簡潔而清晰,具有豐富和強大的類庫。它常被昵稱為膠水語言,能夠把用其他語言製作的各種模塊(尤其是C/C++)很輕松地聯結在一起。常見的一種應用情形是,使用Python快速生成程序的原型(有時甚至是程序的最終界面),然後對其中有特別要求的部分,用更合適的語言改寫,比如3D游戲中的圖形渲染模塊,性能要求特別高,就可以用C/C++重寫,而後封裝為Python可以調用的擴展類庫。需要注意的是在您使用擴展類庫時可能需要考慮平台問題,某些可能不提供跨平台的實現。

D. 如何在Python字元串列表中查找出指定字元所在字元串

re.findall('\\w*{}\\w*'.format(c),','.join(l))
Python 3.5.2 (default, Dec 7 2016, 23:38:49)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux

Type "help", "right", "credits" or "license" for more information.

>>> import re

>>> l=['sfdsd','ddff']

>>> c='s'

>>> re.findall('\\w*{}\\w*'.format(c),','.join(l))
['sfdsd']

E. 編寫程序,從用戶給定字元串中查找某指定的字元.python indexf方法

你好,下面是一些例子:

#!/usr/bin/python
str1="thisisstringexample....wow!!!";
str2="exam";
printstr1.index(str2)
printstr1.index(str2,10)
printstr1.index(str2,40)

F. 怎麼用python寫一個字元串搜索和定位工具

python的正則表達式模塊就可以做到。
導入模塊:
import re

匹配:
re.search(正則表達式, 字元串)

G. python 如何連續查找字元串

python的字元來串可以看做是數組的

所以比如源mystr = "what is your name"

newstr = mystr

if newstr.find("a") >= 0:

newstr = newstr[newstr.find("a"):] #這是後newstr就是第一個a開始之後的字元串

如果不需要包含第一個找到的a,那麼可以這樣:
while newstr.find("a") >= 0:

newstr = newstr[newstr.find("a")+1:] #這樣一致到newstr裡面不包含a為止

H. python如何搜索字元串

如果都是select * from tablename limit 這種格式的,可以通過對from的定位確定表格的名稱 import string a="select a from ssa limit 0,10" b=string.split(a," ") print b c=b.index("from") print c print b[c+1] 程序比較簡單, b的值是['select', 'a', 'from', 'ssa', 'limit', '0,10'] from的位置是2 表的名字是'ssa'

I. python 怎麼在列表中查找含有某個字元

In [3]: data=['qwerfyy','dsfha','fdyythg','efggg']

In [4]: [i for i in data if 'yy' in i]
Out[4]: ['qwerfyy', 'fdyythg']

In [5]: import re

In [6]: [i for i in data if re.search('yy',i)]
Out[6]: ['qwerfyy', 'fdyythg']

J. python如何在字元串中查找指定字元並報出位置

%不太清楚題目,我按理解寫了一段你試試看版
test=str(bin(1770)[2:])
output=[]
for i in test:

output.append[i]

print output
%下面會權得出indices
for i in enumerate[test]:
print i