×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python | Typecasting Input to Integer, Float

Here, we are going to learn how to typecast given input to integer, float in Python? By IncludeHelp Last updated : April 08, 2023

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

Typecasting string input to integer

For typecasting string input to integer, we use int() function, it accepts a string value and returns an integer value.

Syntax

int(input())

Example for typecasting string input to integer

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

# printing input value 
print "num = ", num

Output

Input a value: 10
num =  10

Typecasting string input to float

For typecasting string input to float, we use float() function, it accepts a string value and returns a float value.

Syntax

float(input())

Example for typecasting string input to float

# 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 »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.