For instance, in C we can do something like this:
One solution is to use raw_input() two times.
Another solution is to use split()
Note that we don’t have to explicitly specify split(‘ ‘) because split() uses any whitespace characters as delimiter as default.
One thing to note in above Python code is, both x and y would be of string. We can convert them to int using another line
x, y = [int(x), int(y)] # We can also use list comprehension x, y = [int(x) for x in [x, y]]
Below is complete one line code to read two integer variables from standard input using split and list comprehension
Note that in Python 3, we use input() in place of raw_input().
This article is contributed by Abhishek Shukla. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Python PIL | BoxBlur() method
- Python | sympy.ones() method
- Python | sympy.zeros() method
- Python | sympy.eye() method
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
- Time Functions in Python | Set-2 (Date Manipulations)
- Send mail from your Gmail account using Python
- Python – The new generation Language
- Print Single and Multiple variable in Python
- Increment and Decrement Operators in Python
- str() vs repr() in Python
- Swap two variables in one line in C/C++, Python, PHP and Java
- Generate all permutation of a set in Python
- Class or Static Variables in Python
Improved By : dev_aditya