how to convert user integer input to string in python 1

how to convert user integer input to string in python

int_input = str(input("Write a number:- "))
print(type(int_input))

Here is what the above code is Doing:
1. We are asking the user to input a number.
2. We are storing the input in a variable called int_input.
3. We are printing the type of the variable.

Now, let’s run the code and see what happens.

Write a number:- 10

What? Why is the type of the variable int_input a string?

This is because the input() function always returns a string.

So, if you want to store the input as an integer, you have to explicitly convert it to an integer.

int_input = int(input(“Write a number:- “))
print(type(int_input))

Write a number:- 10

Now, the type of the variable int_input is an integer.

Let’s see another example.

float_input = float(input(“Write a number:- “))
print(type(float_input))

Write a number:- 10.5

Now, the type of the variable float_input is a float.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- 10

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- 0

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- 0.0

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- 0.5

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- True

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- False

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- “Hello”

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- “”

Now, the type of the variable bool_input is a boolean.

Let’s see another example.

bool_input = bool(input(“Write a number:- “))
print(type(bool_input))

Write a number:- ” ”

Now, the type of the variable bool_

Similar Posts