samedi 16 février 2019

What is 'in' called in this condition (to find it in documentation by its name)

I want to check if some words are in a text file, but I need to make the search case-insensitive, so, I need to know how the "in" inside the if condition works, and see its documentation for an option like that.

But I couldn't find it by searching google, I tried to search using terms like "conditional statements python" but still couldn't find it.

#!/usr/bin/python3

search_words = ['Day 3','day 3']

with open('test-target.txt','r') as targetFile:
    for search_word in search_words:
        # put the read cursor again at the begining of the file to prepare it fot next read ^o^
        targetFile.seek(0)

        if search_word in targetFile.read():
            print('yes')
        else:
            print('no')

the file:

Day 3 Lab ......etc
bla bla bla

the output:

yes
no

Aucun commentaire:

Enregistrer un commentaire