Taking value from user in python

Nikhil Pandey
2 min readMay 13, 2023

--

⏮️previous page ⏭️next page

How to input?

We use input() function to take the value from the user. The default data type of input function is string . You can also specify the specific data type to get the input from the user, but for this you have to use another function in combination with input() they are int(), float(), etc according to your requirement in user’s input().

input(prompt string)
prompt string represent a default message in a variable.

While inputting integer values using int() with the input(), make sure that the values being entered must be int type compatible. similarly, while inputting floating point values using float() with input(), make sure that the value being entered must be float type compatible. e.g. (‘abc’ can’t be converted into float or int, hence it is non compatible).

>>># illustrating how to input a value
>>>a=input('Do you like honey?:')
>>>Do you like honey?:
>>>
>>># how to input int type
>>>b=int(input('Your date of birth:'))
>>>Your date of birth:

print() is also a build in function just like input(), int() and float() etc.

print('Hello')
print('i hope you are well:')
print('thanks')
print(10+12) #guess the output

⭐The print() function of python 3 is a way to send output to standard output device, which is normally a monitor.

⭐It auto converts the items to strings i.e. if you are printing a numeric value, it will automatically convert it into equivalent string and print it ; for numeric expressions, it first evaluates them and then converts the result to string, before printing.

⭐It inserts space between items, automatically because the default value of sep argument (separator character) is space(‘ ’).

consider this code :

>>>print('my', 'name', 'is', 'Amit',sep=' ')
my name is Amit
>>>print('my', 'name', 'is', 'Amit',sep='..')
my..name..is..Amit

⭐The end parameter in the print function is used to add any string. At the end of the output of the print statement in python.

⭐By default, the print function ends with a newline.

⭐Passing the whitespace to the end parameter (end=‘ ‘) indicates that the end character has to be identified by whitespace and not a newline.

print('I love to eat',end=' ')
print('mango')
#output
I love to eat mango

That’ll for today! Bye (please mail me if your find anything to be improved. pandeynikhilone@gmail.com) or Have any suggestion! fill form

⏮️previous page ⏭️next page

--

--

Nikhil Pandey

I am a student and a programming nerd. I learn and teach topics to help my fellow readers understand and apply their programming knowledge fluently.