Pour tester si une chaîne de caractères commence par un mot donné on peut utiliser la méthode startswith(), exemple:
>>> s = "Hi, How are you ?"
>>> s.startswith('Hi')
True
>>> s.startswith('Hello')
False
Note: sensible aux majuscules et minuscules:
>>> s.startswith('hi')
False
Références
Liens | Site |
---|---|
Checking whether a string starts with XXXX | stackoverflow |
In python How do i check whether a string starts with special symbol or not? | stackoverflow |
Python String startswith() Method | tutorialspoint |