Method split in python



  • Code:

    a=input().split()
    print(a)
    

    In the case of an entry point '1 2 3'

    Traceback (most recent call last):   File "", line 1, in <module>
            a=input().split()   File "<string>", line 1
        1 2 3
          ^ SyntaxError: invalid syntax
    

    The expression was taken from an example, and should be worked. What could be a nail?



  • It's not. split - That's it. input It's an exception. Why? Indulgence. https://docs.python.org/2/library/functions.html#input Says that... input Makes two things:

    (1) Reading from stdin.

    (2) Everything that's read is done.eval)

    Accordingly, line 1 2 3 cannot be performed because of the wrong syntax. Py3 conduct input() They changed so people don't get confused anymore. Use it. https://docs.python.org/2/library/functions.html#raw_input ♪ Or Python3. You can also use the library. https://pythonhosted.org/six/ so that when you suddenly move to another version, your code doesn't break because Py3 is a function. raw_input() No.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2