Python Check In String
Check In String
Om te kyk of 'n sekere frase of karakter in 'n string voorkom, kan ons die sleutelwoorde
in
of gebruik not in
.
Voorbeeld
Kyk of die frase "ain" in die volgende teks voorkom:
txt = "The rain in Spain stays mainly in the plain"
x = "ain" in txt
print(x)
Voorbeeld
Kyk of die frase "ain" NIE in die volgende teks voorkom nie:
txt = "The rain in Spain stays mainly in the plain"
x = "ain"
not in txt
print(x)