Output using the print() function
Screen par data output show karne ke liye print () function ko use kiya jata hai. aap print () function ke parentheses ke bich arguments likhte ho to yeh screen par output print kar dega. for example……
# output using the print function
print("I love programming.")
output : I love programming
Input using the Input () function
Python me bahut se Built-In functions hote hai. jinme se ek function hai input ( ) function. input () function user se input lene ka kaam karta hai. jab input () function call kiya jata hai to python program ka execution tb tk ruk jata hai jab tk user koi data input na kar de . user ke ENTER or RETURN key press karte hi program Resume ho jata hai. input() function ke parentheses ke bich hum koi bhi String argument de sakte hai. Hum iska ek example dekhte hai….
# Take input from user
quote = input("Type your input here : ")
# print output
print(quote)
Output:
Type your input here : The day is very beautiful
The day is very beautiful
yaha quote ek variable hai jise user se ek String value mili hai. input lene ke baad humne us value ko print kiya.
Ab hum input() function ke baare me thodha or jaante hai…
input () function sabse pehle user se input leta hai fir uske baad wo us expression ko evaluate kar deta hai. iska matlab hai ki python automatically identify karta hai ki user ne jo value di hai uska type kya hai. jaise – String , Number ya List. agar input value galat hoti hai to python ya to syntax error de deta hai ya fir koi exception raised kar deta hai. for example :-
# uses of input () function
number = input("Enter value: ")
name = input("Enter name: ")
# print type of the input values
print("Type of number ",type(number))
print("Type of name ",type(name))
Output :
Enter value : 10
Enter name : python
Type of number <class 'str'>
Type of name <class 'str'>
Note :- Aap jo bhi input () function me enter karte ho… input() function use string me badal deta hai. agar aap koi Integer value bhi enter karte ho to bhi input() function use string bana dega.
suppose aap ek simple python program banana chahte hai. jisme user se Two number input lena hai or un dono numbers ko add karke result print karwana hai. to wo program kuch esa hoga….
num1 = input("Enter First number: ")
num2 = input("Enter Second number: ")
print("Result is: ",num1+num2)
Output:
Enter First number : 5
Enter Second number : 8
Result is: 58
ek baar me dekhne par lagta hai ki yeh program sahi hai. Yessss.. yeh program bilkull sahi hai. lekin jesa aap soch rahe the wesa result aapko show nahi hua. Result 13 hona chahiye tha lekin yaha result 58 hai. jo ki galat hai… is program ka sahi for yeh hoga…
num1 = int(input("Enter First number: "))
num2 = int(input("Enter Second number: "))
print("Result is: ",num1+num2)
Output:
Enter First number : 5
Enter Second number : 8
Result is: 13
yaha humne user input ( Integer value enter karne ke baad bhi string hi hai ) ko explicitly integer me convert kiya int() function ka use karke.
int( input(“—-“) )