User Input in Python

Hello friends how are you, today in this blog i will teach you what is user input, how to take user input, how user input works and programs using user input in a very simple way.

Let's start

USER INPUT IN PYTHON

1.input() is a predefined function which is used to take user input in Python.

2.Default user input is of type string.


name=input("Enter your name:")
print("Your name:",name)
#Printing of data type of name
print(type(name))
"""
***Output***
Enter your name:Aayushi
Your name: Aayushi
<class 'str'="">
"""

1.int() is a predefined function which is used to convert string into integer.


#method 1
number=input("Enter any number:")
print("Type of number:",type(number))
#converting string into integer
num=int(number)
print("Given Number:",num)
#Printing of data type of num
print("Type of number:",type(num))
"""
***Output***
Enter any number:204
Type of number: <class 'str'="">
Given Number: 204
Type of number: <class 'int'="">
"""

#method 2
number=int(input("Enter any number:"))
print("Given Number:",number)
#Printing of data type of number
print("Type of number:",type(number))
"""
***Output***
Enter any number:204
Given Number: 204
Type of number: <class 'int'="">
"""

1.float() is a predefined function which is used to convert string into float.


marks=float(input("Enter your marks:"))
print("Your Marks is:",marks)
#Printing of data type of marks
print("Type of number:",type(marks))
"""
***Output***
Enter your marks:84.2
Your Marks is: 84.2
Type of number: <class 'float'="">
"""

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. 

Try to learn something new and teach something new to other. Thanks.

Post a Comment

0 Comments