R
R
researcher11112017-06-02 17:33:58
Python
researcher1111, 2017-06-02 17:33:58

How can I pass an empty value to a string variable in the split() function?

There is this code in python:

mainstr = input()
main1, main2, main3 = mainstr.split(" ")

If you enter two values, it will give an error that you need to enter three values. How to make it possible to enter two values, and leave the third line empty?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-06-02
@sergey-gornostaev

main1, main2, *_ = mainstr.split(" ")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question