Input/Output
Input/Output
For input we have to enter data ().
for output we have to use Print ().
Input function
1. In python programs, we use the input() function to take any kind of data input from the user through the keyboard.
2. The input() function waits for the user's input and as soon as the user enter the data and process the enter key , the input () function reads that data and assigns it to the variable.
Syntax :- Var-name = Input ()
Print() function is used to display the output on the consol.
Input() function always return string value.
1) var=input("enter data")
2) enter data50
3) print(type(var))
For changing the type of input enter int before Input()
1) var=int(input("enter data"))
2) enter data100
3) print(type(var))
For changing the type of input enter float before Input()
1) var=float(input("enter data"))
2) enter data12.50
3) print(type(var))
For changing the type of input enter bool before Input()
1) var=bool(input("enter data"))
2) enter dataTrue
3) print(type(var))
For changing the type of input to allrounder enter eval before Input()
1)var=eval(input("enter data"))
2)enter data
3)print(type(var))
use of print function is like
input print("hello") it will return
output hello
input print("hello","ankit","rishi") it will return
output hello ankit rishi but if we want to change separator use sep function
input print("hello","ankit","rishi",sep="-") it will return
output hello-ankit-rishi it will change the separator
if we want to print ("hello")
print ("world")
the default nature of output will print hello world in two different line, but if we want the output in single line we have to use end function.
print ("hello",end=" ")
print ("world")
now the output will be in single line with space hello world







Comments
Post a Comment