Python | Typecasting Input to Integer, Float

Here, we are going to learn how to typecast given input to integer, float in Python?
Submitted by IncludeHelp, on September 08, 2018

To input any value, we use input() function - which is an inbuilt function.

Typecasting input to integer

Syntax:

    int(input())

Example:

# input a number
num = int(input("Input a value: "))

# printing input value 
print "num = ", num

Output

Input a value: 10
num =  10

Typecasting Input to float

Syntax:

    float(input())

Example:

# input a number
num = float(input("Input a value: "))

# printing input value 
print "num = ", num

Output

Input a value: 10.23
num =  10.23

Python Basic Programs »



Related Programs

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.