D
D
didrux2020-07-21 18:49:54
Python
didrux, 2020-07-21 18:49:54

How to set a condition in Python if "text" + "something random"?

How to set an if condition in Python so that it reacts to a certain typed text?

a = some-given-text AND some random text
something like if a = 'text' + 'random'
print('Hello')
text is the first parameter given, and random is any random the next word, number...
text23894234, textsdfsdf, text12, textWHAT. so that when I enter all these words, I get print('Hello')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alex-bul, 2020-07-21
@KOT10

There are several options. One of them: make a cut of the string and compare the first conditionally 4 letters. If they are equal to the given string, then the action is performed. Example:

a = 'text2283832939'
if a[:4] == 'text': 
    print('Hello')

S
ScriptKiddo, 2020-07-21
@ScriptKiddo

a = 'textJKKLXCK23'

if a.startswith('text'):
    print('Hello')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question