I started my first Python script and it works but i wanted to expand it but i cant seem to find a way to verify if there exists a parameter:
prompt2 = prompt1.split(" ")
elif prompt2 == ‘test’:
I tried multiple ways to check if prompt2 contains anything or exists, can anyone help me out?
i tried that and it was the only thing that worked yes, but there is no way to check if prompt2 exists or contains anything? i tried this with len too and checked if the var exists if i remember correct.
… i cant seem to find a way to verify if there exists a parameter:
Assuming prompt is a string, you can test it’s “truthiness” and optionally debug it with print:
message_1 = "Hello world!"
message_2 = ""
args = prompt.split()
if not args:
print("DEBUG: No args found")
# Out: ['Hello', 'world!']
# DEBUG: No args found
# Out: 
Splitting a string returns a list (of arguments in this case). If there are no arguments, the list will be empty. The boolean of an empty container is False, so you can directly test the container in an if statement.