Home python Split Method in Python

Split Method in Python





a = input (). Split ()
Print (A)

When submitting to enter a line '1 2 3'

traceback: file ", line 1, in & lt; module & gt;
    a = input (). Split () File "& lt; String & GT;", Line 1
  1 2 3.
   ^ Syntaxerror: Invalid Syntax

The expression is taken from the example, should work. What could be a snag?

Answer 1, Authority 100%

This is not Split – this input drops out an exception. And why? Beltness. Documentation says what – Input makes two things:

1) reads from stdin.

2) All that is read is executed (Eval ).

, respectively, the 1 2 3 line cannot be completed due to the wrong syntax. In Py3, the behavior of input () changed so that people are no longer confused. Use Raw_input . Or python3. You can also use the library Six so that with a sudden move to another version, your code has not broken, because in the PY3 function Raw_input ( ) missing.

Answer 2, Authority 30%

Simply replace input () Raw_input ()

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions