-1

I have texts coming from the database and I try to check text with specific numbers and characters. I need to know how to check a word if the first letter is "1" or not.

How could I do this?

simbad
  • 21
  • 1
  • 1

2 Answers2

5

You can access the first letter of the word in the same way as the first item in a list. But remember that the first index is 0.

if word[0] == "1":
    print("First letter is 1")
The Otterlord
  • 1,680
  • 10
  • 20
4

You can use text.startswith("1") which will return True or False depending on whether your text starts with '1' or not