X
X
XWR2021-08-12 21:43:22
Python
XWR, 2021-08-12 21:43:22

Python check if string starts with "@"?

How to check if a string starts with "@"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-08-12
@XWR

Choose:

import re
text1 = '@0'
text2 = '0'
print(text1, text1.startswith('@'))
print(text2, text2.startswith('@'))
print(text1, bool(re.match('^@', text1)))
print(text2, bool(re.match('^@', text2)))
print(text1, text1[:1] == '@')
print(text2, text2[:1] == '@')
# @0 True
# 0 False
# @0 True
# 0 False
# @0 True
# 0 False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question