Two values from one input in python?












30















This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python?



For instance, in C I can do something like this: scanf("%d %d", &var1, &var2). However, I can't figure out what the Python equivalent of that is. I figured it would just be something like var1, var2 = input("Enter two numbers here: "), but that doesn't work and I'm not complaining because it wouldn't make a whole lot of sense if it did.



Does anyone out there know a good way to do this elegantly and concisely?










share|improve this question

























  • Very similar recent question: stackoverflow.com/questions/959412/parsing-numbers-in-python

    – Nicolas Dumazet
    Jun 7 '09 at 5:51
















30















This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python?



For instance, in C I can do something like this: scanf("%d %d", &var1, &var2). However, I can't figure out what the Python equivalent of that is. I figured it would just be something like var1, var2 = input("Enter two numbers here: "), but that doesn't work and I'm not complaining because it wouldn't make a whole lot of sense if it did.



Does anyone out there know a good way to do this elegantly and concisely?










share|improve this question

























  • Very similar recent question: stackoverflow.com/questions/959412/parsing-numbers-in-python

    – Nicolas Dumazet
    Jun 7 '09 at 5:51














30












30








30


20






This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python?



For instance, in C I can do something like this: scanf("%d %d", &var1, &var2). However, I can't figure out what the Python equivalent of that is. I figured it would just be something like var1, var2 = input("Enter two numbers here: "), but that doesn't work and I'm not complaining because it wouldn't make a whole lot of sense if it did.



Does anyone out there know a good way to do this elegantly and concisely?










share|improve this question
















This is somewhat of a simple question and I hate to ask it here, but I can't seem the find the answer anywhere else: is it possible to get multiple values from the user in one line of Python?



For instance, in C I can do something like this: scanf("%d %d", &var1, &var2). However, I can't figure out what the Python equivalent of that is. I figured it would just be something like var1, var2 = input("Enter two numbers here: "), but that doesn't work and I'm not complaining because it wouldn't make a whole lot of sense if it did.



Does anyone out there know a good way to do this elegantly and concisely?







python variables input






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 23 '11 at 18:21









Jonta

241524




241524










asked Jun 7 '09 at 5:27







Donovan




















  • Very similar recent question: stackoverflow.com/questions/959412/parsing-numbers-in-python

    – Nicolas Dumazet
    Jun 7 '09 at 5:51



















  • Very similar recent question: stackoverflow.com/questions/959412/parsing-numbers-in-python

    – Nicolas Dumazet
    Jun 7 '09 at 5:51

















Very similar recent question: stackoverflow.com/questions/959412/parsing-numbers-in-python

– Nicolas Dumazet
Jun 7 '09 at 5:51





Very similar recent question: stackoverflow.com/questions/959412/parsing-numbers-in-python

– Nicolas Dumazet
Jun 7 '09 at 5:51












18 Answers
18






active

oldest

votes


















51














The Python way to map



printf("Enter two numbers here: ");
scanf("%d %d", &var1, &var2)


would be



var1, var2 = raw_input("Enter two numbers here: ").split()


Note that we don't have to explicitly specify split(' ') because split() uses any whitespace characters as delimiter as default. That means if we simply called split() then the user could have separated the numbers using tabs, if he really wanted, and also spaces.,



Python has dynamic typing so there is no need to specify %d. However, if you ran the above then var1 and var2 would be both Strings. You can convert them to int using another line



var1, var2 = [int(var1), int(var2)]


Or you could use list comprehension



var1, var2 = [int(x) for x in [var1, var2]]


To sum it up, you could have done the whole thing with this one-liner:



# Python 3
var1, var2 = [int(x) for x in input("Enter two numbers here: ").split()]

# Python 2
var1, var2 = [int(x) for x in raw_input("Enter two numbers here: ").split()]





share|improve this answer

































    10














    You can't really do it the C way (I think) but a pythonic way of doing this would be (if your 'inputs' have spaces in between them):



    raw_answer = raw_input()
    answers = raw_answer.split(' ') # list of 'answers'


    So you could rewrite your try to:



    var1, var2 = raw_input("enter two numbers:").split(' ')


    Note that this it somewhat less flexible than using the 'first' solution (for example if you add a space at the end this will already break).



    Also be aware that var1 and var2 will still be strings with this method when not cast to int.






    share|improve this answer

































      8














      In Python 2.*, input lets the user enter any expression, e.g. a tuple:



      >>> a, b = input('Two numbers please (with a comma in between): ')
      Two numbers please (with a comma in between): 23, 45
      >>> print a, b
      23 45


      In Python 3.*, input is like 2.*'s raw_input, returning you a string that's just what the user typed (rather than evaling it as 2.* used to do on input), so you'll have to .split, and/or eval, &c but you'll also be MUCH more in control of the whole thing.






      share|improve this answer
























      • Oh noes. Please never do this: input() allows for arbitrary code execution. Just type exit('pwned!') at the input prompt and see what happens.

        – 9000
        Mar 21 '17 at 20:18













      • @9000 I got a ValueError exception. That's perfect. So it's not that something harmful you meant. So no worries using input() now.

        – unclexo
        Jul 22 '18 at 6:44



















      6














      If you need to take two integers say a,b in python you can use map function.

      Suppose input is,




      1
      5 3
      1 2 3 4 5


      where 1 represent test case, 5 represent number of values and 3 represents a task value and in next line given 5 values, we can take such input using this method in PYTH 2.x Version.



      testCases=int(raw_input())
      number, taskValue = map(int, raw_input().split())
      array = map(int, raw_input().split())


      You can replace 'int' in map() with another datatype needed.






      share|improve this answer































        3














        All input will be through a string. It's up to you to process that string after you've received it. Unless that is, you use the eval(input()) method, but that isn't recommended for most situations anyway.



        input_string = raw_input("Enter 2 numbers here: ")
        a, b = split_string_into_numbers(input_string)
        do_stuff(a, b)





        share|improve this answer































          3














          You have to use the split() method which splits the input into two different inputs. Whatever you pass into the split is looked for and the input is split from there. In most cases its the white space.



          For example, You give the input 23 24 25. You expect 3 different inputs like



          num1 = 23
          num2 = 24
          num3 = 25


          So in Python, You can do



          num1,num2,num3 = input().split(" ")





          share|improve this answer































            2














            Check this handy function:



            def gets(*types):
            return tuple([types[i](val) for i, val in enumerate(raw_input().split(' '))])

            # usage:
            a, b, c = gets(int, float, str)





            share|improve this answer



















            • 1





              Index access is not needed! return tuple(parser(value) for (parser, value) in zip(types, raw_input(prompt).split(' '))).

              – 9000
              Mar 21 '17 at 20:22



















            2














            The solution I found is the following:





            Ask the user to enter two numbers separated by a comma or other character



            value = input("Enter 2 numbers (separated by a comma): ")



            Then, the string is split: n takes the first value and m the second one



            n,m = value.split(',')



            Finally, to use them as integers, it is necessary to convert them



            n, m = int(n), int(m)









            share|improve this answer































              1














              The easiest way that I found for myself was using split function with input
              Like you have two variable a,b



              a,b=input("Enter two numbers").split()


              That's it.
              there is one more method(explicit method)
              Eg- you want to take input in three values



              value=input("Enter the line")
              a,b,c=value.split()


              EASY..






              share|improve this answer































                1














                This is a sample code to take two inputs seperated by split command and delimiter as ","





                >>> var1, var2 = input("enter two numbers:").split(',')
                >>>enter two numbers:2,3
                >>> var1
                '2'
                >>> var2
                '3'





                Other variations of delimiters that can be used are as below :
                var1, var2 = input("enter two numbers:").split(',')
                var1, var2 = input("enter two numbers:").split(';')
                var1, var2 = input("enter two numbers:").split('/')
                var1, var2 = input("enter two numbers:").split(' ')
                var1, var2 = input("enter two numbers:").split('~')






                share|improve this answer































                  1














                  For n number of inputs declare the variable as an empty list and use the same syntax to proceed:



                  >>> x=input('Enter value of a and b').split(",")
                  Enter value of a and b
                  1,2,3,4
                  >>> x
                  ['1', '2', '3', '4']





                  share|improve this answer

































                    0














                    a,b=[int(x) for x in input().split()]
                    print(a,b)


                    Output




                    10 8




                    10 8






                    share|improve this answer































                      0














                      In Python 3, raw_input() was renamed to input().



                      input([prompt])



                      If the prompt argument is present, it is written to standard output
                      without a trailing newline. The function then reads a line from input,
                      converts it to a string (stripping a trailing newline), and returns
                      that. When EOF is read, EOFError is raised.




                      So you can do this way



                      x, y = input('Enter two numbers separating by a space: ').split();
                      print(int(x) + int(y))


                      If you do not put two numbers using a space you would get a ValueError exception. So that is good to go.



                      N.B. If you need old behavior of input(), use eval(input())






                      share|improve this answer































                        0














                        I tried this in Python 3 , seems to work fine .



                        a, b = map(int,input().split())

                        print(a)

                        print(b)



                        Input : 3 44



                        Output :



                        3



                        44







                        share|improve this answer

































                          0














                          Two inputs separated by space:



                          x,y=input().split()





                          share|improve this answer































                            0














                            This solution is being used for converting multiple string like ("22 44 112 2 34") to an integer list and you can access to the values in a list.



                            n = input("") # Like : "22 343 455 54445 22332"

                            if n[:-1] != " ":
                            n += " "

                            char = ""
                            list =

                            for i in n :
                            if i != " ":
                            char += i
                            elif i == " ":
                            list.append(int(char))
                            char = ""

                            print(list) # Be happy :))))





                            share|improve this answer































                              0














                              You can do this way



                              a, b = map(int, input().split())


                              OR



                              a, b = input().split()
                              print(int(a))


                              OR



                              MyList = list(map(int, input().split()))
                              a = MyList[0]
                              b = MyList[1]





                              share|improve this answer































                                0














                                if we want to two inputs in a single line so, the code is are as follows enter code here



                                x,y=input().split(" ")

                                print(x,y)


                                after giving value as input we have to give spaces between them because of split(" ") function or method.



                                but these values are of string type if to perform some arithmetic operations we have to convert the type of x,y are as follows
                                int(x),int(y)



                                we can do this also with the help of list in python.enter code here



                                list1=list(map(int,input().split()))
                                print(list1)


                                this list gives the elements in int type






                                share|improve this answer










                                New contributor




                                JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.




















                                  Your Answer






                                  StackExchange.ifUsing("editor", function () {
                                  StackExchange.using("externalEditor", function () {
                                  StackExchange.using("snippets", function () {
                                  StackExchange.snippets.init();
                                  });
                                  });
                                  }, "code-snippets");

                                  StackExchange.ready(function() {
                                  var channelOptions = {
                                  tags: "".split(" "),
                                  id: "1"
                                  };
                                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                  StackExchange.using("externalEditor", function() {
                                  // Have to fire editor after snippets, if snippets enabled
                                  if (StackExchange.settings.snippets.snippetsEnabled) {
                                  StackExchange.using("snippets", function() {
                                  createEditor();
                                  });
                                  }
                                  else {
                                  createEditor();
                                  }
                                  });

                                  function createEditor() {
                                  StackExchange.prepareEditor({
                                  heartbeatType: 'answer',
                                  autoActivateHeartbeat: false,
                                  convertImagesToLinks: true,
                                  noModals: true,
                                  showLowRepImageUploadWarning: true,
                                  reputationToPostImages: 10,
                                  bindNavPrevention: true,
                                  postfix: "",
                                  imageUploader: {
                                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                  allowUrls: true
                                  },
                                  onDemand: true,
                                  discardSelector: ".discard-answer"
                                  ,immediatelyShowMarkdownHelp:true
                                  });


                                  }
                                  });














                                  draft saved

                                  draft discarded


















                                  StackExchange.ready(
                                  function () {
                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f961263%2ftwo-values-from-one-input-in-python%23new-answer', 'question_page');
                                  }
                                  );

                                  Post as a guest















                                  Required, but never shown
























                                  18 Answers
                                  18






                                  active

                                  oldest

                                  votes








                                  18 Answers
                                  18






                                  active

                                  oldest

                                  votes









                                  active

                                  oldest

                                  votes






                                  active

                                  oldest

                                  votes









                                  51














                                  The Python way to map



                                  printf("Enter two numbers here: ");
                                  scanf("%d %d", &var1, &var2)


                                  would be



                                  var1, var2 = raw_input("Enter two numbers here: ").split()


                                  Note that we don't have to explicitly specify split(' ') because split() uses any whitespace characters as delimiter as default. That means if we simply called split() then the user could have separated the numbers using tabs, if he really wanted, and also spaces.,



                                  Python has dynamic typing so there is no need to specify %d. However, if you ran the above then var1 and var2 would be both Strings. You can convert them to int using another line



                                  var1, var2 = [int(var1), int(var2)]


                                  Or you could use list comprehension



                                  var1, var2 = [int(x) for x in [var1, var2]]


                                  To sum it up, you could have done the whole thing with this one-liner:



                                  # Python 3
                                  var1, var2 = [int(x) for x in input("Enter two numbers here: ").split()]

                                  # Python 2
                                  var1, var2 = [int(x) for x in raw_input("Enter two numbers here: ").split()]





                                  share|improve this answer






























                                    51














                                    The Python way to map



                                    printf("Enter two numbers here: ");
                                    scanf("%d %d", &var1, &var2)


                                    would be



                                    var1, var2 = raw_input("Enter two numbers here: ").split()


                                    Note that we don't have to explicitly specify split(' ') because split() uses any whitespace characters as delimiter as default. That means if we simply called split() then the user could have separated the numbers using tabs, if he really wanted, and also spaces.,



                                    Python has dynamic typing so there is no need to specify %d. However, if you ran the above then var1 and var2 would be both Strings. You can convert them to int using another line



                                    var1, var2 = [int(var1), int(var2)]


                                    Or you could use list comprehension



                                    var1, var2 = [int(x) for x in [var1, var2]]


                                    To sum it up, you could have done the whole thing with this one-liner:



                                    # Python 3
                                    var1, var2 = [int(x) for x in input("Enter two numbers here: ").split()]

                                    # Python 2
                                    var1, var2 = [int(x) for x in raw_input("Enter two numbers here: ").split()]





                                    share|improve this answer




























                                      51












                                      51








                                      51







                                      The Python way to map



                                      printf("Enter two numbers here: ");
                                      scanf("%d %d", &var1, &var2)


                                      would be



                                      var1, var2 = raw_input("Enter two numbers here: ").split()


                                      Note that we don't have to explicitly specify split(' ') because split() uses any whitespace characters as delimiter as default. That means if we simply called split() then the user could have separated the numbers using tabs, if he really wanted, and also spaces.,



                                      Python has dynamic typing so there is no need to specify %d. However, if you ran the above then var1 and var2 would be both Strings. You can convert them to int using another line



                                      var1, var2 = [int(var1), int(var2)]


                                      Or you could use list comprehension



                                      var1, var2 = [int(x) for x in [var1, var2]]


                                      To sum it up, you could have done the whole thing with this one-liner:



                                      # Python 3
                                      var1, var2 = [int(x) for x in input("Enter two numbers here: ").split()]

                                      # Python 2
                                      var1, var2 = [int(x) for x in raw_input("Enter two numbers here: ").split()]





                                      share|improve this answer















                                      The Python way to map



                                      printf("Enter two numbers here: ");
                                      scanf("%d %d", &var1, &var2)


                                      would be



                                      var1, var2 = raw_input("Enter two numbers here: ").split()


                                      Note that we don't have to explicitly specify split(' ') because split() uses any whitespace characters as delimiter as default. That means if we simply called split() then the user could have separated the numbers using tabs, if he really wanted, and also spaces.,



                                      Python has dynamic typing so there is no need to specify %d. However, if you ran the above then var1 and var2 would be both Strings. You can convert them to int using another line



                                      var1, var2 = [int(var1), int(var2)]


                                      Or you could use list comprehension



                                      var1, var2 = [int(x) for x in [var1, var2]]


                                      To sum it up, you could have done the whole thing with this one-liner:



                                      # Python 3
                                      var1, var2 = [int(x) for x in input("Enter two numbers here: ").split()]

                                      # Python 2
                                      var1, var2 = [int(x) for x in raw_input("Enter two numbers here: ").split()]






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Jan 23 '18 at 2:06

























                                      answered Jun 7 '09 at 5:59









                                      kizzx2kizzx2

                                      11k136476




                                      11k136476

























                                          10














                                          You can't really do it the C way (I think) but a pythonic way of doing this would be (if your 'inputs' have spaces in between them):



                                          raw_answer = raw_input()
                                          answers = raw_answer.split(' ') # list of 'answers'


                                          So you could rewrite your try to:



                                          var1, var2 = raw_input("enter two numbers:").split(' ')


                                          Note that this it somewhat less flexible than using the 'first' solution (for example if you add a space at the end this will already break).



                                          Also be aware that var1 and var2 will still be strings with this method when not cast to int.






                                          share|improve this answer






























                                            10














                                            You can't really do it the C way (I think) but a pythonic way of doing this would be (if your 'inputs' have spaces in between them):



                                            raw_answer = raw_input()
                                            answers = raw_answer.split(' ') # list of 'answers'


                                            So you could rewrite your try to:



                                            var1, var2 = raw_input("enter two numbers:").split(' ')


                                            Note that this it somewhat less flexible than using the 'first' solution (for example if you add a space at the end this will already break).



                                            Also be aware that var1 and var2 will still be strings with this method when not cast to int.






                                            share|improve this answer




























                                              10












                                              10








                                              10







                                              You can't really do it the C way (I think) but a pythonic way of doing this would be (if your 'inputs' have spaces in between them):



                                              raw_answer = raw_input()
                                              answers = raw_answer.split(' ') # list of 'answers'


                                              So you could rewrite your try to:



                                              var1, var2 = raw_input("enter two numbers:").split(' ')


                                              Note that this it somewhat less flexible than using the 'first' solution (for example if you add a space at the end this will already break).



                                              Also be aware that var1 and var2 will still be strings with this method when not cast to int.






                                              share|improve this answer















                                              You can't really do it the C way (I think) but a pythonic way of doing this would be (if your 'inputs' have spaces in between them):



                                              raw_answer = raw_input()
                                              answers = raw_answer.split(' ') # list of 'answers'


                                              So you could rewrite your try to:



                                              var1, var2 = raw_input("enter two numbers:").split(' ')


                                              Note that this it somewhat less flexible than using the 'first' solution (for example if you add a space at the end this will already break).



                                              Also be aware that var1 and var2 will still be strings with this method when not cast to int.







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Jun 7 '09 at 5:45

























                                              answered Jun 7 '09 at 5:39









                                              ChristopheDChristopheD

                                              80.4k21143165




                                              80.4k21143165























                                                  8














                                                  In Python 2.*, input lets the user enter any expression, e.g. a tuple:



                                                  >>> a, b = input('Two numbers please (with a comma in between): ')
                                                  Two numbers please (with a comma in between): 23, 45
                                                  >>> print a, b
                                                  23 45


                                                  In Python 3.*, input is like 2.*'s raw_input, returning you a string that's just what the user typed (rather than evaling it as 2.* used to do on input), so you'll have to .split, and/or eval, &c but you'll also be MUCH more in control of the whole thing.






                                                  share|improve this answer
























                                                  • Oh noes. Please never do this: input() allows for arbitrary code execution. Just type exit('pwned!') at the input prompt and see what happens.

                                                    – 9000
                                                    Mar 21 '17 at 20:18













                                                  • @9000 I got a ValueError exception. That's perfect. So it's not that something harmful you meant. So no worries using input() now.

                                                    – unclexo
                                                    Jul 22 '18 at 6:44
















                                                  8














                                                  In Python 2.*, input lets the user enter any expression, e.g. a tuple:



                                                  >>> a, b = input('Two numbers please (with a comma in between): ')
                                                  Two numbers please (with a comma in between): 23, 45
                                                  >>> print a, b
                                                  23 45


                                                  In Python 3.*, input is like 2.*'s raw_input, returning you a string that's just what the user typed (rather than evaling it as 2.* used to do on input), so you'll have to .split, and/or eval, &c but you'll also be MUCH more in control of the whole thing.






                                                  share|improve this answer
























                                                  • Oh noes. Please never do this: input() allows for arbitrary code execution. Just type exit('pwned!') at the input prompt and see what happens.

                                                    – 9000
                                                    Mar 21 '17 at 20:18













                                                  • @9000 I got a ValueError exception. That's perfect. So it's not that something harmful you meant. So no worries using input() now.

                                                    – unclexo
                                                    Jul 22 '18 at 6:44














                                                  8












                                                  8








                                                  8







                                                  In Python 2.*, input lets the user enter any expression, e.g. a tuple:



                                                  >>> a, b = input('Two numbers please (with a comma in between): ')
                                                  Two numbers please (with a comma in between): 23, 45
                                                  >>> print a, b
                                                  23 45


                                                  In Python 3.*, input is like 2.*'s raw_input, returning you a string that's just what the user typed (rather than evaling it as 2.* used to do on input), so you'll have to .split, and/or eval, &c but you'll also be MUCH more in control of the whole thing.






                                                  share|improve this answer













                                                  In Python 2.*, input lets the user enter any expression, e.g. a tuple:



                                                  >>> a, b = input('Two numbers please (with a comma in between): ')
                                                  Two numbers please (with a comma in between): 23, 45
                                                  >>> print a, b
                                                  23 45


                                                  In Python 3.*, input is like 2.*'s raw_input, returning you a string that's just what the user typed (rather than evaling it as 2.* used to do on input), so you'll have to .split, and/or eval, &c but you'll also be MUCH more in control of the whole thing.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Jun 7 '09 at 6:19









                                                  Alex MartelliAlex Martelli

                                                  627k12810401280




                                                  627k12810401280













                                                  • Oh noes. Please never do this: input() allows for arbitrary code execution. Just type exit('pwned!') at the input prompt and see what happens.

                                                    – 9000
                                                    Mar 21 '17 at 20:18













                                                  • @9000 I got a ValueError exception. That's perfect. So it's not that something harmful you meant. So no worries using input() now.

                                                    – unclexo
                                                    Jul 22 '18 at 6:44



















                                                  • Oh noes. Please never do this: input() allows for arbitrary code execution. Just type exit('pwned!') at the input prompt and see what happens.

                                                    – 9000
                                                    Mar 21 '17 at 20:18













                                                  • @9000 I got a ValueError exception. That's perfect. So it's not that something harmful you meant. So no worries using input() now.

                                                    – unclexo
                                                    Jul 22 '18 at 6:44

















                                                  Oh noes. Please never do this: input() allows for arbitrary code execution. Just type exit('pwned!') at the input prompt and see what happens.

                                                  – 9000
                                                  Mar 21 '17 at 20:18







                                                  Oh noes. Please never do this: input() allows for arbitrary code execution. Just type exit('pwned!') at the input prompt and see what happens.

                                                  – 9000
                                                  Mar 21 '17 at 20:18















                                                  @9000 I got a ValueError exception. That's perfect. So it's not that something harmful you meant. So no worries using input() now.

                                                  – unclexo
                                                  Jul 22 '18 at 6:44





                                                  @9000 I got a ValueError exception. That's perfect. So it's not that something harmful you meant. So no worries using input() now.

                                                  – unclexo
                                                  Jul 22 '18 at 6:44











                                                  6














                                                  If you need to take two integers say a,b in python you can use map function.

                                                  Suppose input is,




                                                  1
                                                  5 3
                                                  1 2 3 4 5


                                                  where 1 represent test case, 5 represent number of values and 3 represents a task value and in next line given 5 values, we can take such input using this method in PYTH 2.x Version.



                                                  testCases=int(raw_input())
                                                  number, taskValue = map(int, raw_input().split())
                                                  array = map(int, raw_input().split())


                                                  You can replace 'int' in map() with another datatype needed.






                                                  share|improve this answer




























                                                    6














                                                    If you need to take two integers say a,b in python you can use map function.

                                                    Suppose input is,




                                                    1
                                                    5 3
                                                    1 2 3 4 5


                                                    where 1 represent test case, 5 represent number of values and 3 represents a task value and in next line given 5 values, we can take such input using this method in PYTH 2.x Version.



                                                    testCases=int(raw_input())
                                                    number, taskValue = map(int, raw_input().split())
                                                    array = map(int, raw_input().split())


                                                    You can replace 'int' in map() with another datatype needed.






                                                    share|improve this answer


























                                                      6












                                                      6








                                                      6







                                                      If you need to take two integers say a,b in python you can use map function.

                                                      Suppose input is,




                                                      1
                                                      5 3
                                                      1 2 3 4 5


                                                      where 1 represent test case, 5 represent number of values and 3 represents a task value and in next line given 5 values, we can take such input using this method in PYTH 2.x Version.



                                                      testCases=int(raw_input())
                                                      number, taskValue = map(int, raw_input().split())
                                                      array = map(int, raw_input().split())


                                                      You can replace 'int' in map() with another datatype needed.






                                                      share|improve this answer













                                                      If you need to take two integers say a,b in python you can use map function.

                                                      Suppose input is,




                                                      1
                                                      5 3
                                                      1 2 3 4 5


                                                      where 1 represent test case, 5 represent number of values and 3 represents a task value and in next line given 5 values, we can take such input using this method in PYTH 2.x Version.



                                                      testCases=int(raw_input())
                                                      number, taskValue = map(int, raw_input().split())
                                                      array = map(int, raw_input().split())


                                                      You can replace 'int' in map() with another datatype needed.







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered May 24 '15 at 7:42









                                                      Rishabh PrasadRishabh Prasad

                                                      1441211




                                                      1441211























                                                          3














                                                          All input will be through a string. It's up to you to process that string after you've received it. Unless that is, you use the eval(input()) method, but that isn't recommended for most situations anyway.



                                                          input_string = raw_input("Enter 2 numbers here: ")
                                                          a, b = split_string_into_numbers(input_string)
                                                          do_stuff(a, b)





                                                          share|improve this answer




























                                                            3














                                                            All input will be through a string. It's up to you to process that string after you've received it. Unless that is, you use the eval(input()) method, but that isn't recommended for most situations anyway.



                                                            input_string = raw_input("Enter 2 numbers here: ")
                                                            a, b = split_string_into_numbers(input_string)
                                                            do_stuff(a, b)





                                                            share|improve this answer


























                                                              3












                                                              3








                                                              3







                                                              All input will be through a string. It's up to you to process that string after you've received it. Unless that is, you use the eval(input()) method, but that isn't recommended for most situations anyway.



                                                              input_string = raw_input("Enter 2 numbers here: ")
                                                              a, b = split_string_into_numbers(input_string)
                                                              do_stuff(a, b)





                                                              share|improve this answer













                                                              All input will be through a string. It's up to you to process that string after you've received it. Unless that is, you use the eval(input()) method, but that isn't recommended for most situations anyway.



                                                              input_string = raw_input("Enter 2 numbers here: ")
                                                              a, b = split_string_into_numbers(input_string)
                                                              do_stuff(a, b)






                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Jun 7 '09 at 6:26









                                                              sykorasykora

                                                              60.3k95567




                                                              60.3k95567























                                                                  3














                                                                  You have to use the split() method which splits the input into two different inputs. Whatever you pass into the split is looked for and the input is split from there. In most cases its the white space.



                                                                  For example, You give the input 23 24 25. You expect 3 different inputs like



                                                                  num1 = 23
                                                                  num2 = 24
                                                                  num3 = 25


                                                                  So in Python, You can do



                                                                  num1,num2,num3 = input().split(" ")





                                                                  share|improve this answer




























                                                                    3














                                                                    You have to use the split() method which splits the input into two different inputs. Whatever you pass into the split is looked for and the input is split from there. In most cases its the white space.



                                                                    For example, You give the input 23 24 25. You expect 3 different inputs like



                                                                    num1 = 23
                                                                    num2 = 24
                                                                    num3 = 25


                                                                    So in Python, You can do



                                                                    num1,num2,num3 = input().split(" ")





                                                                    share|improve this answer


























                                                                      3












                                                                      3








                                                                      3







                                                                      You have to use the split() method which splits the input into two different inputs. Whatever you pass into the split is looked for and the input is split from there. In most cases its the white space.



                                                                      For example, You give the input 23 24 25. You expect 3 different inputs like



                                                                      num1 = 23
                                                                      num2 = 24
                                                                      num3 = 25


                                                                      So in Python, You can do



                                                                      num1,num2,num3 = input().split(" ")





                                                                      share|improve this answer













                                                                      You have to use the split() method which splits the input into two different inputs. Whatever you pass into the split is looked for and the input is split from there. In most cases its the white space.



                                                                      For example, You give the input 23 24 25. You expect 3 different inputs like



                                                                      num1 = 23
                                                                      num2 = 24
                                                                      num3 = 25


                                                                      So in Python, You can do



                                                                      num1,num2,num3 = input().split(" ")






                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Jan 24 '17 at 5:40









                                                                      devDeejaydevDeejay

                                                                      750816




                                                                      750816























                                                                          2














                                                                          Check this handy function:



                                                                          def gets(*types):
                                                                          return tuple([types[i](val) for i, val in enumerate(raw_input().split(' '))])

                                                                          # usage:
                                                                          a, b, c = gets(int, float, str)





                                                                          share|improve this answer



















                                                                          • 1





                                                                            Index access is not needed! return tuple(parser(value) for (parser, value) in zip(types, raw_input(prompt).split(' '))).

                                                                            – 9000
                                                                            Mar 21 '17 at 20:22
















                                                                          2














                                                                          Check this handy function:



                                                                          def gets(*types):
                                                                          return tuple([types[i](val) for i, val in enumerate(raw_input().split(' '))])

                                                                          # usage:
                                                                          a, b, c = gets(int, float, str)





                                                                          share|improve this answer



















                                                                          • 1





                                                                            Index access is not needed! return tuple(parser(value) for (parser, value) in zip(types, raw_input(prompt).split(' '))).

                                                                            – 9000
                                                                            Mar 21 '17 at 20:22














                                                                          2












                                                                          2








                                                                          2







                                                                          Check this handy function:



                                                                          def gets(*types):
                                                                          return tuple([types[i](val) for i, val in enumerate(raw_input().split(' '))])

                                                                          # usage:
                                                                          a, b, c = gets(int, float, str)





                                                                          share|improve this answer













                                                                          Check this handy function:



                                                                          def gets(*types):
                                                                          return tuple([types[i](val) for i, val in enumerate(raw_input().split(' '))])

                                                                          # usage:
                                                                          a, b, c = gets(int, float, str)






                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Feb 16 '14 at 21:15









                                                                          Mikołaj RozwadowskiMikołaj Rozwadowski

                                                                          863611




                                                                          863611








                                                                          • 1





                                                                            Index access is not needed! return tuple(parser(value) for (parser, value) in zip(types, raw_input(prompt).split(' '))).

                                                                            – 9000
                                                                            Mar 21 '17 at 20:22














                                                                          • 1





                                                                            Index access is not needed! return tuple(parser(value) for (parser, value) in zip(types, raw_input(prompt).split(' '))).

                                                                            – 9000
                                                                            Mar 21 '17 at 20:22








                                                                          1




                                                                          1





                                                                          Index access is not needed! return tuple(parser(value) for (parser, value) in zip(types, raw_input(prompt).split(' '))).

                                                                          – 9000
                                                                          Mar 21 '17 at 20:22





                                                                          Index access is not needed! return tuple(parser(value) for (parser, value) in zip(types, raw_input(prompt).split(' '))).

                                                                          – 9000
                                                                          Mar 21 '17 at 20:22











                                                                          2














                                                                          The solution I found is the following:





                                                                          Ask the user to enter two numbers separated by a comma or other character



                                                                          value = input("Enter 2 numbers (separated by a comma): ")



                                                                          Then, the string is split: n takes the first value and m the second one



                                                                          n,m = value.split(',')



                                                                          Finally, to use them as integers, it is necessary to convert them



                                                                          n, m = int(n), int(m)









                                                                          share|improve this answer




























                                                                            2














                                                                            The solution I found is the following:





                                                                            Ask the user to enter two numbers separated by a comma or other character



                                                                            value = input("Enter 2 numbers (separated by a comma): ")



                                                                            Then, the string is split: n takes the first value and m the second one



                                                                            n,m = value.split(',')



                                                                            Finally, to use them as integers, it is necessary to convert them



                                                                            n, m = int(n), int(m)









                                                                            share|improve this answer


























                                                                              2












                                                                              2








                                                                              2







                                                                              The solution I found is the following:





                                                                              Ask the user to enter two numbers separated by a comma or other character



                                                                              value = input("Enter 2 numbers (separated by a comma): ")



                                                                              Then, the string is split: n takes the first value and m the second one



                                                                              n,m = value.split(',')



                                                                              Finally, to use them as integers, it is necessary to convert them



                                                                              n, m = int(n), int(m)









                                                                              share|improve this answer













                                                                              The solution I found is the following:





                                                                              Ask the user to enter two numbers separated by a comma or other character



                                                                              value = input("Enter 2 numbers (separated by a comma): ")



                                                                              Then, the string is split: n takes the first value and m the second one



                                                                              n,m = value.split(',')



                                                                              Finally, to use them as integers, it is necessary to convert them



                                                                              n, m = int(n), int(m)










                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Sep 5 '17 at 21:46









                                                                              E. ZavalaE. Zavala

                                                                              212




                                                                              212























                                                                                  1














                                                                                  The easiest way that I found for myself was using split function with input
                                                                                  Like you have two variable a,b



                                                                                  a,b=input("Enter two numbers").split()


                                                                                  That's it.
                                                                                  there is one more method(explicit method)
                                                                                  Eg- you want to take input in three values



                                                                                  value=input("Enter the line")
                                                                                  a,b,c=value.split()


                                                                                  EASY..






                                                                                  share|improve this answer




























                                                                                    1














                                                                                    The easiest way that I found for myself was using split function with input
                                                                                    Like you have two variable a,b



                                                                                    a,b=input("Enter two numbers").split()


                                                                                    That's it.
                                                                                    there is one more method(explicit method)
                                                                                    Eg- you want to take input in three values



                                                                                    value=input("Enter the line")
                                                                                    a,b,c=value.split()


                                                                                    EASY..






                                                                                    share|improve this answer


























                                                                                      1












                                                                                      1








                                                                                      1







                                                                                      The easiest way that I found for myself was using split function with input
                                                                                      Like you have two variable a,b



                                                                                      a,b=input("Enter two numbers").split()


                                                                                      That's it.
                                                                                      there is one more method(explicit method)
                                                                                      Eg- you want to take input in three values



                                                                                      value=input("Enter the line")
                                                                                      a,b,c=value.split()


                                                                                      EASY..






                                                                                      share|improve this answer













                                                                                      The easiest way that I found for myself was using split function with input
                                                                                      Like you have two variable a,b



                                                                                      a,b=input("Enter two numbers").split()


                                                                                      That's it.
                                                                                      there is one more method(explicit method)
                                                                                      Eg- you want to take input in three values



                                                                                      value=input("Enter the line")
                                                                                      a,b,c=value.split()


                                                                                      EASY..







                                                                                      share|improve this answer












                                                                                      share|improve this answer



                                                                                      share|improve this answer










                                                                                      answered Jul 8 '17 at 10:06









                                                                                      user8258851user8258851

                                                                                      165




                                                                                      165























                                                                                          1














                                                                                          This is a sample code to take two inputs seperated by split command and delimiter as ","





                                                                                          >>> var1, var2 = input("enter two numbers:").split(',')
                                                                                          >>>enter two numbers:2,3
                                                                                          >>> var1
                                                                                          '2'
                                                                                          >>> var2
                                                                                          '3'





                                                                                          Other variations of delimiters that can be used are as below :
                                                                                          var1, var2 = input("enter two numbers:").split(',')
                                                                                          var1, var2 = input("enter two numbers:").split(';')
                                                                                          var1, var2 = input("enter two numbers:").split('/')
                                                                                          var1, var2 = input("enter two numbers:").split(' ')
                                                                                          var1, var2 = input("enter two numbers:").split('~')






                                                                                          share|improve this answer




























                                                                                            1














                                                                                            This is a sample code to take two inputs seperated by split command and delimiter as ","





                                                                                            >>> var1, var2 = input("enter two numbers:").split(',')
                                                                                            >>>enter two numbers:2,3
                                                                                            >>> var1
                                                                                            '2'
                                                                                            >>> var2
                                                                                            '3'





                                                                                            Other variations of delimiters that can be used are as below :
                                                                                            var1, var2 = input("enter two numbers:").split(',')
                                                                                            var1, var2 = input("enter two numbers:").split(';')
                                                                                            var1, var2 = input("enter two numbers:").split('/')
                                                                                            var1, var2 = input("enter two numbers:").split(' ')
                                                                                            var1, var2 = input("enter two numbers:").split('~')






                                                                                            share|improve this answer


























                                                                                              1












                                                                                              1








                                                                                              1







                                                                                              This is a sample code to take two inputs seperated by split command and delimiter as ","





                                                                                              >>> var1, var2 = input("enter two numbers:").split(',')
                                                                                              >>>enter two numbers:2,3
                                                                                              >>> var1
                                                                                              '2'
                                                                                              >>> var2
                                                                                              '3'





                                                                                              Other variations of delimiters that can be used are as below :
                                                                                              var1, var2 = input("enter two numbers:").split(',')
                                                                                              var1, var2 = input("enter two numbers:").split(';')
                                                                                              var1, var2 = input("enter two numbers:").split('/')
                                                                                              var1, var2 = input("enter two numbers:").split(' ')
                                                                                              var1, var2 = input("enter two numbers:").split('~')






                                                                                              share|improve this answer













                                                                                              This is a sample code to take two inputs seperated by split command and delimiter as ","





                                                                                              >>> var1, var2 = input("enter two numbers:").split(',')
                                                                                              >>>enter two numbers:2,3
                                                                                              >>> var1
                                                                                              '2'
                                                                                              >>> var2
                                                                                              '3'





                                                                                              Other variations of delimiters that can be used are as below :
                                                                                              var1, var2 = input("enter two numbers:").split(',')
                                                                                              var1, var2 = input("enter two numbers:").split(';')
                                                                                              var1, var2 = input("enter two numbers:").split('/')
                                                                                              var1, var2 = input("enter two numbers:").split(' ')
                                                                                              var1, var2 = input("enter two numbers:").split('~')







                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered Jul 12 '17 at 13:48









                                                                                              Jagannath BanerjeeJagannath Banerjee

                                                                                              26926




                                                                                              26926























                                                                                                  1














                                                                                                  For n number of inputs declare the variable as an empty list and use the same syntax to proceed:



                                                                                                  >>> x=input('Enter value of a and b').split(",")
                                                                                                  Enter value of a and b
                                                                                                  1,2,3,4
                                                                                                  >>> x
                                                                                                  ['1', '2', '3', '4']





                                                                                                  share|improve this answer






























                                                                                                    1














                                                                                                    For n number of inputs declare the variable as an empty list and use the same syntax to proceed:



                                                                                                    >>> x=input('Enter value of a and b').split(",")
                                                                                                    Enter value of a and b
                                                                                                    1,2,3,4
                                                                                                    >>> x
                                                                                                    ['1', '2', '3', '4']





                                                                                                    share|improve this answer




























                                                                                                      1












                                                                                                      1








                                                                                                      1







                                                                                                      For n number of inputs declare the variable as an empty list and use the same syntax to proceed:



                                                                                                      >>> x=input('Enter value of a and b').split(",")
                                                                                                      Enter value of a and b
                                                                                                      1,2,3,4
                                                                                                      >>> x
                                                                                                      ['1', '2', '3', '4']





                                                                                                      share|improve this answer















                                                                                                      For n number of inputs declare the variable as an empty list and use the same syntax to proceed:



                                                                                                      >>> x=input('Enter value of a and b').split(",")
                                                                                                      Enter value of a and b
                                                                                                      1,2,3,4
                                                                                                      >>> x
                                                                                                      ['1', '2', '3', '4']






                                                                                                      share|improve this answer














                                                                                                      share|improve this answer



                                                                                                      share|improve this answer








                                                                                                      edited Jun 28 '18 at 14:26









                                                                                                      Dadep

                                                                                                      2,33041632




                                                                                                      2,33041632










                                                                                                      answered Jun 28 '18 at 14:08









                                                                                                      Premgi kumarPremgi kumar

                                                                                                      111




                                                                                                      111























                                                                                                          0














                                                                                                          a,b=[int(x) for x in input().split()]
                                                                                                          print(a,b)


                                                                                                          Output




                                                                                                          10 8




                                                                                                          10 8






                                                                                                          share|improve this answer




























                                                                                                            0














                                                                                                            a,b=[int(x) for x in input().split()]
                                                                                                            print(a,b)


                                                                                                            Output




                                                                                                            10 8




                                                                                                            10 8






                                                                                                            share|improve this answer


























                                                                                                              0












                                                                                                              0








                                                                                                              0







                                                                                                              a,b=[int(x) for x in input().split()]
                                                                                                              print(a,b)


                                                                                                              Output




                                                                                                              10 8




                                                                                                              10 8






                                                                                                              share|improve this answer













                                                                                                              a,b=[int(x) for x in input().split()]
                                                                                                              print(a,b)


                                                                                                              Output




                                                                                                              10 8




                                                                                                              10 8







                                                                                                              share|improve this answer












                                                                                                              share|improve this answer



                                                                                                              share|improve this answer










                                                                                                              answered Jul 7 '18 at 17:34









                                                                                                              Siddharth jhaSiddharth jha

                                                                                                              12




                                                                                                              12























                                                                                                                  0














                                                                                                                  In Python 3, raw_input() was renamed to input().



                                                                                                                  input([prompt])



                                                                                                                  If the prompt argument is present, it is written to standard output
                                                                                                                  without a trailing newline. The function then reads a line from input,
                                                                                                                  converts it to a string (stripping a trailing newline), and returns
                                                                                                                  that. When EOF is read, EOFError is raised.




                                                                                                                  So you can do this way



                                                                                                                  x, y = input('Enter two numbers separating by a space: ').split();
                                                                                                                  print(int(x) + int(y))


                                                                                                                  If you do not put two numbers using a space you would get a ValueError exception. So that is good to go.



                                                                                                                  N.B. If you need old behavior of input(), use eval(input())






                                                                                                                  share|improve this answer




























                                                                                                                    0














                                                                                                                    In Python 3, raw_input() was renamed to input().



                                                                                                                    input([prompt])



                                                                                                                    If the prompt argument is present, it is written to standard output
                                                                                                                    without a trailing newline. The function then reads a line from input,
                                                                                                                    converts it to a string (stripping a trailing newline), and returns
                                                                                                                    that. When EOF is read, EOFError is raised.




                                                                                                                    So you can do this way



                                                                                                                    x, y = input('Enter two numbers separating by a space: ').split();
                                                                                                                    print(int(x) + int(y))


                                                                                                                    If you do not put two numbers using a space you would get a ValueError exception. So that is good to go.



                                                                                                                    N.B. If you need old behavior of input(), use eval(input())






                                                                                                                    share|improve this answer


























                                                                                                                      0












                                                                                                                      0








                                                                                                                      0







                                                                                                                      In Python 3, raw_input() was renamed to input().



                                                                                                                      input([prompt])



                                                                                                                      If the prompt argument is present, it is written to standard output
                                                                                                                      without a trailing newline. The function then reads a line from input,
                                                                                                                      converts it to a string (stripping a trailing newline), and returns
                                                                                                                      that. When EOF is read, EOFError is raised.




                                                                                                                      So you can do this way



                                                                                                                      x, y = input('Enter two numbers separating by a space: ').split();
                                                                                                                      print(int(x) + int(y))


                                                                                                                      If you do not put two numbers using a space you would get a ValueError exception. So that is good to go.



                                                                                                                      N.B. If you need old behavior of input(), use eval(input())






                                                                                                                      share|improve this answer













                                                                                                                      In Python 3, raw_input() was renamed to input().



                                                                                                                      input([prompt])



                                                                                                                      If the prompt argument is present, it is written to standard output
                                                                                                                      without a trailing newline. The function then reads a line from input,
                                                                                                                      converts it to a string (stripping a trailing newline), and returns
                                                                                                                      that. When EOF is read, EOFError is raised.




                                                                                                                      So you can do this way



                                                                                                                      x, y = input('Enter two numbers separating by a space: ').split();
                                                                                                                      print(int(x) + int(y))


                                                                                                                      If you do not put two numbers using a space you would get a ValueError exception. So that is good to go.



                                                                                                                      N.B. If you need old behavior of input(), use eval(input())







                                                                                                                      share|improve this answer












                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer










                                                                                                                      answered Jul 22 '18 at 7:18









                                                                                                                      unclexounclexo

                                                                                                                      1,295511




                                                                                                                      1,295511























                                                                                                                          0














                                                                                                                          I tried this in Python 3 , seems to work fine .



                                                                                                                          a, b = map(int,input().split())

                                                                                                                          print(a)

                                                                                                                          print(b)



                                                                                                                          Input : 3 44



                                                                                                                          Output :



                                                                                                                          3



                                                                                                                          44







                                                                                                                          share|improve this answer






























                                                                                                                            0














                                                                                                                            I tried this in Python 3 , seems to work fine .



                                                                                                                            a, b = map(int,input().split())

                                                                                                                            print(a)

                                                                                                                            print(b)



                                                                                                                            Input : 3 44



                                                                                                                            Output :



                                                                                                                            3



                                                                                                                            44







                                                                                                                            share|improve this answer




























                                                                                                                              0












                                                                                                                              0








                                                                                                                              0







                                                                                                                              I tried this in Python 3 , seems to work fine .



                                                                                                                              a, b = map(int,input().split())

                                                                                                                              print(a)

                                                                                                                              print(b)



                                                                                                                              Input : 3 44



                                                                                                                              Output :



                                                                                                                              3



                                                                                                                              44







                                                                                                                              share|improve this answer















                                                                                                                              I tried this in Python 3 , seems to work fine .



                                                                                                                              a, b = map(int,input().split())

                                                                                                                              print(a)

                                                                                                                              print(b)



                                                                                                                              Input : 3 44



                                                                                                                              Output :



                                                                                                                              3



                                                                                                                              44








                                                                                                                              share|improve this answer














                                                                                                                              share|improve this answer



                                                                                                                              share|improve this answer








                                                                                                                              edited Oct 26 '18 at 18:21









                                                                                                                              Madhur Bhaiya

                                                                                                                              19.6k62236




                                                                                                                              19.6k62236










                                                                                                                              answered Oct 26 '18 at 18:03









                                                                                                                              user10564553user10564553

                                                                                                                              1




                                                                                                                              1























                                                                                                                                  0














                                                                                                                                  Two inputs separated by space:



                                                                                                                                  x,y=input().split()





                                                                                                                                  share|improve this answer




























                                                                                                                                    0














                                                                                                                                    Two inputs separated by space:



                                                                                                                                    x,y=input().split()





                                                                                                                                    share|improve this answer


























                                                                                                                                      0












                                                                                                                                      0








                                                                                                                                      0







                                                                                                                                      Two inputs separated by space:



                                                                                                                                      x,y=input().split()





                                                                                                                                      share|improve this answer













                                                                                                                                      Two inputs separated by space:



                                                                                                                                      x,y=input().split()






                                                                                                                                      share|improve this answer












                                                                                                                                      share|improve this answer



                                                                                                                                      share|improve this answer










                                                                                                                                      answered Nov 16 '18 at 18:02









                                                                                                                                      ZeinabZeinab

                                                                                                                                      7915




                                                                                                                                      7915























                                                                                                                                          0














                                                                                                                                          This solution is being used for converting multiple string like ("22 44 112 2 34") to an integer list and you can access to the values in a list.



                                                                                                                                          n = input("") # Like : "22 343 455 54445 22332"

                                                                                                                                          if n[:-1] != " ":
                                                                                                                                          n += " "

                                                                                                                                          char = ""
                                                                                                                                          list =

                                                                                                                                          for i in n :
                                                                                                                                          if i != " ":
                                                                                                                                          char += i
                                                                                                                                          elif i == " ":
                                                                                                                                          list.append(int(char))
                                                                                                                                          char = ""

                                                                                                                                          print(list) # Be happy :))))





                                                                                                                                          share|improve this answer




























                                                                                                                                            0














                                                                                                                                            This solution is being used for converting multiple string like ("22 44 112 2 34") to an integer list and you can access to the values in a list.



                                                                                                                                            n = input("") # Like : "22 343 455 54445 22332"

                                                                                                                                            if n[:-1] != " ":
                                                                                                                                            n += " "

                                                                                                                                            char = ""
                                                                                                                                            list =

                                                                                                                                            for i in n :
                                                                                                                                            if i != " ":
                                                                                                                                            char += i
                                                                                                                                            elif i == " ":
                                                                                                                                            list.append(int(char))
                                                                                                                                            char = ""

                                                                                                                                            print(list) # Be happy :))))





                                                                                                                                            share|improve this answer


























                                                                                                                                              0












                                                                                                                                              0








                                                                                                                                              0







                                                                                                                                              This solution is being used for converting multiple string like ("22 44 112 2 34") to an integer list and you can access to the values in a list.



                                                                                                                                              n = input("") # Like : "22 343 455 54445 22332"

                                                                                                                                              if n[:-1] != " ":
                                                                                                                                              n += " "

                                                                                                                                              char = ""
                                                                                                                                              list =

                                                                                                                                              for i in n :
                                                                                                                                              if i != " ":
                                                                                                                                              char += i
                                                                                                                                              elif i == " ":
                                                                                                                                              list.append(int(char))
                                                                                                                                              char = ""

                                                                                                                                              print(list) # Be happy :))))





                                                                                                                                              share|improve this answer













                                                                                                                                              This solution is being used for converting multiple string like ("22 44 112 2 34") to an integer list and you can access to the values in a list.



                                                                                                                                              n = input("") # Like : "22 343 455 54445 22332"

                                                                                                                                              if n[:-1] != " ":
                                                                                                                                              n += " "

                                                                                                                                              char = ""
                                                                                                                                              list =

                                                                                                                                              for i in n :
                                                                                                                                              if i != " ":
                                                                                                                                              char += i
                                                                                                                                              elif i == " ":
                                                                                                                                              list.append(int(char))
                                                                                                                                              char = ""

                                                                                                                                              print(list) # Be happy :))))






                                                                                                                                              share|improve this answer












                                                                                                                                              share|improve this answer



                                                                                                                                              share|improve this answer










                                                                                                                                              answered Nov 24 '18 at 21:33









                                                                                                                                              Ali MontajebiAli Montajebi

                                                                                                                                              1




                                                                                                                                              1























                                                                                                                                                  0














                                                                                                                                                  You can do this way



                                                                                                                                                  a, b = map(int, input().split())


                                                                                                                                                  OR



                                                                                                                                                  a, b = input().split()
                                                                                                                                                  print(int(a))


                                                                                                                                                  OR



                                                                                                                                                  MyList = list(map(int, input().split()))
                                                                                                                                                  a = MyList[0]
                                                                                                                                                  b = MyList[1]





                                                                                                                                                  share|improve this answer




























                                                                                                                                                    0














                                                                                                                                                    You can do this way



                                                                                                                                                    a, b = map(int, input().split())


                                                                                                                                                    OR



                                                                                                                                                    a, b = input().split()
                                                                                                                                                    print(int(a))


                                                                                                                                                    OR



                                                                                                                                                    MyList = list(map(int, input().split()))
                                                                                                                                                    a = MyList[0]
                                                                                                                                                    b = MyList[1]





                                                                                                                                                    share|improve this answer


























                                                                                                                                                      0












                                                                                                                                                      0








                                                                                                                                                      0







                                                                                                                                                      You can do this way



                                                                                                                                                      a, b = map(int, input().split())


                                                                                                                                                      OR



                                                                                                                                                      a, b = input().split()
                                                                                                                                                      print(int(a))


                                                                                                                                                      OR



                                                                                                                                                      MyList = list(map(int, input().split()))
                                                                                                                                                      a = MyList[0]
                                                                                                                                                      b = MyList[1]





                                                                                                                                                      share|improve this answer













                                                                                                                                                      You can do this way



                                                                                                                                                      a, b = map(int, input().split())


                                                                                                                                                      OR



                                                                                                                                                      a, b = input().split()
                                                                                                                                                      print(int(a))


                                                                                                                                                      OR



                                                                                                                                                      MyList = list(map(int, input().split()))
                                                                                                                                                      a = MyList[0]
                                                                                                                                                      b = MyList[1]






                                                                                                                                                      share|improve this answer












                                                                                                                                                      share|improve this answer



                                                                                                                                                      share|improve this answer










                                                                                                                                                      answered Dec 20 '18 at 0:01









                                                                                                                                                      vishwarajvishwaraj

                                                                                                                                                      33924




                                                                                                                                                      33924























                                                                                                                                                          0














                                                                                                                                                          if we want to two inputs in a single line so, the code is are as follows enter code here



                                                                                                                                                          x,y=input().split(" ")

                                                                                                                                                          print(x,y)


                                                                                                                                                          after giving value as input we have to give spaces between them because of split(" ") function or method.



                                                                                                                                                          but these values are of string type if to perform some arithmetic operations we have to convert the type of x,y are as follows
                                                                                                                                                          int(x),int(y)



                                                                                                                                                          we can do this also with the help of list in python.enter code here



                                                                                                                                                          list1=list(map(int,input().split()))
                                                                                                                                                          print(list1)


                                                                                                                                                          this list gives the elements in int type






                                                                                                                                                          share|improve this answer










                                                                                                                                                          New contributor




                                                                                                                                                          JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                          Check out our Code of Conduct.

























                                                                                                                                                            0














                                                                                                                                                            if we want to two inputs in a single line so, the code is are as follows enter code here



                                                                                                                                                            x,y=input().split(" ")

                                                                                                                                                            print(x,y)


                                                                                                                                                            after giving value as input we have to give spaces between them because of split(" ") function or method.



                                                                                                                                                            but these values are of string type if to perform some arithmetic operations we have to convert the type of x,y are as follows
                                                                                                                                                            int(x),int(y)



                                                                                                                                                            we can do this also with the help of list in python.enter code here



                                                                                                                                                            list1=list(map(int,input().split()))
                                                                                                                                                            print(list1)


                                                                                                                                                            this list gives the elements in int type






                                                                                                                                                            share|improve this answer










                                                                                                                                                            New contributor




                                                                                                                                                            JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                            Check out our Code of Conduct.























                                                                                                                                                              0












                                                                                                                                                              0








                                                                                                                                                              0







                                                                                                                                                              if we want to two inputs in a single line so, the code is are as follows enter code here



                                                                                                                                                              x,y=input().split(" ")

                                                                                                                                                              print(x,y)


                                                                                                                                                              after giving value as input we have to give spaces between them because of split(" ") function or method.



                                                                                                                                                              but these values are of string type if to perform some arithmetic operations we have to convert the type of x,y are as follows
                                                                                                                                                              int(x),int(y)



                                                                                                                                                              we can do this also with the help of list in python.enter code here



                                                                                                                                                              list1=list(map(int,input().split()))
                                                                                                                                                              print(list1)


                                                                                                                                                              this list gives the elements in int type






                                                                                                                                                              share|improve this answer










                                                                                                                                                              New contributor




                                                                                                                                                              JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                              Check out our Code of Conduct.










                                                                                                                                                              if we want to two inputs in a single line so, the code is are as follows enter code here



                                                                                                                                                              x,y=input().split(" ")

                                                                                                                                                              print(x,y)


                                                                                                                                                              after giving value as input we have to give spaces between them because of split(" ") function or method.



                                                                                                                                                              but these values are of string type if to perform some arithmetic operations we have to convert the type of x,y are as follows
                                                                                                                                                              int(x),int(y)



                                                                                                                                                              we can do this also with the help of list in python.enter code here



                                                                                                                                                              list1=list(map(int,input().split()))
                                                                                                                                                              print(list1)


                                                                                                                                                              this list gives the elements in int type







                                                                                                                                                              share|improve this answer










                                                                                                                                                              New contributor




                                                                                                                                                              JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                              Check out our Code of Conduct.









                                                                                                                                                              share|improve this answer



                                                                                                                                                              share|improve this answer








                                                                                                                                                              edited Feb 17 at 13:16





















                                                                                                                                                              New contributor




                                                                                                                                                              JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                              Check out our Code of Conduct.









                                                                                                                                                              answered Feb 17 at 12:39









                                                                                                                                                              JATIN BEHUNEJATIN BEHUNE

                                                                                                                                                              12




                                                                                                                                                              12




                                                                                                                                                              New contributor




                                                                                                                                                              JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                              Check out our Code of Conduct.





                                                                                                                                                              New contributor





                                                                                                                                                              JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                              Check out our Code of Conduct.






                                                                                                                                                              JATIN BEHUNE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                                                              Check out our Code of Conduct.






























                                                                                                                                                                  draft saved

                                                                                                                                                                  draft discarded




















































                                                                                                                                                                  Thanks for contributing an answer to Stack Overflow!


                                                                                                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                                                                                                  But avoid



                                                                                                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                                                                                                  To learn more, see our tips on writing great answers.




                                                                                                                                                                  draft saved


                                                                                                                                                                  draft discarded














                                                                                                                                                                  StackExchange.ready(
                                                                                                                                                                  function () {
                                                                                                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f961263%2ftwo-values-from-one-input-in-python%23new-answer', 'question_page');
                                                                                                                                                                  }
                                                                                                                                                                  );

                                                                                                                                                                  Post as a guest















                                                                                                                                                                  Required, but never shown





















































                                                                                                                                                                  Required, but never shown














                                                                                                                                                                  Required, but never shown












                                                                                                                                                                  Required, but never shown







                                                                                                                                                                  Required, but never shown

































                                                                                                                                                                  Required, but never shown














                                                                                                                                                                  Required, but never shown












                                                                                                                                                                  Required, but never shown







                                                                                                                                                                  Required, but never shown







                                                                                                                                                                  Popular posts from this blog

                                                                                                                                                                  404 Error Contact Form 7 ajax form submitting

                                                                                                                                                                  How to know if a Active Directory user can login interactively

                                                                                                                                                                  Refactoring coordinates for Minecraft Pi buildings written in Python