0% found this document useful (0 votes)
14 views1 page

The Input Function: My - Age ( (My - Age) )

The document discusses how the input() function in Python accepts user input as a string and how to convert it to numeric types like int and float using int() and float() functions.

Uploaded by

Karthik K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

The Input Function: My - Age ( (My - Age) )

The document discusses how the input() function in Python accepts user input as a string and how to convert it to numeric types like int and float using int() and float() functions.

Uploaded by

Karthik K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The input() function

In this notebook we look at how user input can be obtained and stored in variables. The input() function returns values
whose data type is string. When you wish to accept numeric values from the user, the input function must be used in
combination with the int() or float() function

In [1]:

my_age = input() #Note the lack of a space between the prompt and the user's response.
print(type(my_age))
# What is the type of my_age?

12
<class 'str'>

In [2]:

my_age = input('Enter your age:') #Note the lack of a space between the prompt and the user's resp
onse.
print(type(my_age))
# What is the type of my_age?

Enter your age:45


<class 'str'>

In [3]:
my_str_age = input('Enter your age: ')
my_age = int(my_str_age) # Now what is the type of my_age
print(type(my_age))

Enter your age: 45


<class 'int'>

In [1]:
price = float(input('Enter the price of the book: '))
print(price)
# What is the type of price? What happens if you use int() instead of float()?

Enter the price of the book: 56


56.0

You might also like