Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Grep keyword từ Python Tuple

Tuple of strings: tìm exact match dùng in operator.

tpl = ("Hello", "world", "Foo", "bar")
print("world" in tpl)  # True

Tìm substring: lặp tuple, dùng in trên string.

for i in tpl:
    if "orld" in i:
        print("Found orld in " + i)

Kết quả: Found orld in world