5
votes

I've used this method before but can't find it in any of my codes so here I am on Stack Overflow :) What I'm trying to do is split an input into two( the user is asked to enter two digits separated by space). How would you call the first digit a and the second digit b ? The code so far doesn't seem to work.

a,b= input(split" "("Please enter two digits separated by space"))
2
Consider attempting to locate relevant documentation before posting syntactically invalid code in a question. To wit: this is really basic stuff; please make a concerted effort. - Matt Ball
-1 for lack of research effort. There are tonnes of dupes for this. - Games Brainiac
Also downvote for showing zero motivation for doing basic research - Andreas Jung

2 Answers

11
votes

You're calling the function wrongly.

>>> "hello world".split()
['hello', 'world']

split slits a string by a space by default, but you can change this behavior:

>>> "hello, world".split(',')
['hello', ' world']

In your case:

a,b= input("Please enter two digits separated by space").split()
4
votes

The str.split() function is an attribute of the type str (string). To call it, you do:

input("Please enter two digits separated by space").split()

Note that .split(" ") isn't needed as that is what it is by default.