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: SUNAGAR Your name: SUNAGAR <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:206 Type of number: <class 'str'=""> Given Number: 208 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:205 Given Number: 205 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:94.5 Your Marks is: 94.5 Type of number: <class 'float'=""> """