
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to read input from console
Suppose we have to take firstname and lastname from console and write a prompt like "Hello <firstname> <lastname>, you are welcome!". To get the result we can use the format() class.We can placeholder into the string using {}, then pass arguments into format() function.
So, if the input is like Ashish Dutta, then the output will be "Hello Ashish Dutta, you are welcome!"
To solve this, we will follow these steps −
fn := take first input from the console
ln := take second input from the console
ret := "Hello a {} {}, you are welcome!" then call format with this string like format(fn, ln)
return ret
Example
Let us see the following implementation to get better understanding
def solve(): fn = input() ln = input() ret = "Hello {} {}, you are welcome!".format(fn, ln) return ret print(solve())
Input
Ashish Dutta
Output
Hello Ashish Dutta, you are welcome!
- Related Articles
- Way to read input from console in C#
- Ways to read input from console in Java
- Taking input from console in Python
- Haskell program to read numbers from standard input
- Read integers from console in Java
- Java Program to Read The Number From Standard Input
- Kotlin Program to Read The Number From Standard Input
- How to Read The Number From Standard Input in Swift Program?
- How to read a line from the console in C#?
- Java Program to read the next byte of data from the input stream
- How to read data from user using the Console class in Java?
- How to read data from PDF file and display on console in Java?
- Get number from user input and display in console with JavaScript
- How can we read from standard input in Java?
- Java program to read numbers from users

Advertisements