0% found this document useful (0 votes)
79 views

Taking Input From Console in Python

The document discusses taking input from the console in Python. It explains that the console is a command line interpreter that takes user input and executes Python commands. It then describes how to take input in Python using the input() function and how to typecast the input to integer, float, or string. It also discusses taking multiple inputs from the user and printing the output.

Uploaded by

Darshan M M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Taking Input From Console in Python

The document discusses taking input from the console in Python. It explains that the console is a command line interpreter that takes user input and executes Python commands. It then describes how to take input in Python using the input() function and how to typecast the input to integer, float, or string. It also discusses taking multiple inputs from the user and printing the output.

Uploaded by

Darshan M M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

 Tutorialskeyboard_arrow_down

 Studentkeyboard_arrow_down
 Courses
 Jobskeyboard_arrow_down

Sign In
 Sign In
 Home
 Courses
 Algorithmskeyboard_arrow_down
 Data Structureskeyboard_arrow_down
 Languageskeyboard_arrow_down
 Interview Cornerkeyboard_arrow_down
 GATEkeyboard_arrow_down
 CS Subjectskeyboard_arrow_down
 Studentkeyboard_arrow_down
 Jobskeyboard_arrow_down
 GBlog
 Puzzles
 What's New ?
Introductionexpand_more
Input/Outputexpand_more

o Taking input in Python


o Taking input from console in Python
o Taking multiple inputs from user in Python
o Python | Output using print() function
o How to print without newline in Python?
o Python end parameter in print()
o Python | sep parameter in print()
o Python | Output Formatting
Operatorsexpand_more
Data Typesexpand_more
Control Flowexpand_more
Functionsexpand_more
Python OOPexpand_more
Exception Handlingexpand_more
File handlingexpand_more
Python Regexexpand_more
Python Collectionsexpand_more
Python NumPyexpand_more
Python Pandasexpand_more
Python Djangoexpand_more
Python JSONexpand_more
Python CSVexpand_more
Python MySQLexpand_more
Python MongoDBexpand_more
Python OpenCVexpand_more
Python Seleniumexpand_more
Python Tkinterexpand_more
Python Kivyexpand_more
Python Examples and Quizexpand_more
Taking input from console in Python
Last Updated: 27-11-2020
What is Console in Python? Console (also called Shell) is basically a command line interpreter that takes
input from the user i.e one command at a time and interprets it. If it is error free then it runs the command and
gives required output otherwise shows the error message. A Python Console looks like this.

Here we write command and to execute the command just press enter key and your command will be
interpreted.
For coding in Python you must know the basics of the console used in Python.
The primary prompt of the python console is the three greater than symbols
>>>
You are free to write the next command on the shell only when after executing the first command these
prompts have appeared. The Python Console accepts command in Python which you write after the prompt.

Accepting Input from Console


User enters the values in the Console and that value is then used in the program as it was required.
To take input from the user we make use of a built-in function input().
filter_none
edit
play_arrow
brightness_4
# input
input1 = input()
  
# output
print(input1)
We can also type cast this input to integer, float or string by specifying the input() function inside the type.
1. Typecasting the input to Integer: There might be conditions when you might require integer
input from user/Console, the following code takes two input(integer/float) from console and
typecasts them to integer then prints the sum.
filter_none
edit
play_arrow
brightness_4
# input
num1 = int(input())
num2 = int(input())
  
# printing the sum in integer
print(num1 + num2)
2. Typecasting the input to Float: To convert the input to float the following code will work out.
filter_none
edit
play_arrow
brightness_4
# input
num1 = float(input())
num2 = float(input())
  
# printing the sum in float
print(num1 + num2)
3. Typecasting the input to String: All kind of input can be converted to string type whether they
are float or integer. We make use of keyword str for typecasting.
filter_none
edit
play_arrow
brightness_4
# input
string = str(input())
  
# output
print(string)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn
the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python
DS Course.

Recommended Posts:
 Difference between console.dir and console.log
 Difference between console.dir and console.log
 Taking input in Python
 Taking Input from User in R Programming
 Taking Input from Users in Julia
 Ways to read input from console in Java
 Taking multiple inputs from user in Python
 Python VLC MediaPlayer – Taking Screenshot
 Taking Screenshots using pyscreenshot in Python
 Position after taking N steps to the right and left in an alternate manner
 Program to multiply two Matrix by taking data from user
 Min operations to reduce N by multiplying by any number or taking square root
 Python | Create simple animation for console-based application
 HTML | DOM console.timeEnd() Method
 Console.ReadLine() Method in C#
 Console.SetWindowSize() Method in C#
 Console.ResetColor() Method in C#
 Console.ReadKey() Method in C#
 Console.SetBufferSize() Method in C#
 Console.Read() Method in C#

DikshaTewari
Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article
using contribute.geeksforgeeks.org or mail your article to [email protected]. See your article
appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags : 
Python

School Programming

python-input-output

thumb_up
38

To-do  Done
1.1
Based on 19 vote(s)
Improve Article
 
 
Please write to us at [email protected] to report any issue with the above content.
Post navigation
Previous
first_page TCS National Qualifier 2 Coding Question.
Next
last_pagePython | Extracting rows using Pandas .iloc[]

Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.

Load Comments

Most popular in Python


 Python map() function
 Adding new column to existing DataFrame in Pandas
 Iterate over a list in Python
 Python program to convert a list to string
 Read a file line by line in Python

Most visited in School Programming


 Arrays in C/C++
 Inheritance in C++
 Reverse a string in Java
 C++ Data Types
 C++ Classes and Objects

room5th Floor, A-118,


Sector-136, Noida, Uttar Pradesh - 201305

[email protected]

 Company
 About Us
 Careers
 Privacy Policy
 Contact Us
 Learn
 Algorithms
 Data Structures
 Languages
 CS Subjects
 Video Tutorials
 Practice
 Courses
 Company-wise
 Topic-wise
 How to begin?
 Contribute
 Write an Article
 Write Interview Experience
 Internships
 Videos
@geeksforgeeks , Some rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you
have read and understood our Cookie Policy & Privacy PolicyGot It !

You might also like