You could add an asterisk to the info variable:
program, *info = input("->").split()
if program == 'search':
print(info[0])
elif program == 'hello':
print("do")
else:
print("Error")
This result in info being a list of everything after the first element of the split input. If you enter search youtube.com
, the variable info will contain ['youtube.com']
. If you enter hello
, the variable info will contain nothing, i.e. []
.
Note that I also added a list access to the info variable in line 4, where it is printed.
More information on how to solve this and/or why this works can be found here, where default values in unpacking are discussed.
Edit: As @Steve pointed out, this becomes problematic if only search
is entered, because you'd try to access the first element of an empty list. To prevent this, you can add an extra check to your code:
program, *info = input("->").split()
if program == 'search':
if not info:
print("Error, nothing to search for")
else:
print(info[0])
elif program == 'hello':
print("do")
else:
print("Error")