-min.jpg)
input output in python
Input and Output Introduction
Python में input/output के लिए कुछ functions का इस्तेमाल किया जाता है | User के keyboard से input लेने के लिए 'input()' इस function का इस्तेमाल किया जाता है और User के screen पर कुछ print करने के लिए 'print()' इस function का इस्तेमाल किया जाता है |
input() Function for taking User Input Python में जब User से कुछ letters या numbers लेने की बारी आती है तब 'input()' function का इस्तेमाल किया जाता है |
Syntax for input() Function
input("SomeText")
Parameter :
Some Text : Optional.User को क्या input देना है उसके बारे में यहाँ पर कुछ text दिया जाता है | Example for 'input()'
Function Source Code :
a = input("Enter your name : ") print("Your name is", a)Output :
Enter your name : Maxon Your name is Maxon
जब User; numeric, letters या special symbols; input लेते है तो उसका data type 'string' होता है |
Source Code :
a = input("Enter Number : ") print("Entered input's type is", type(a))Output :
Enter Number : 4 Entered input's type is
Python Type Conversion
जब उस String data type को Number(int, float, complex number) में convert करना हो तो Type Conversion functions का इस्तेमाल करना पड़ता है |
Source Code :
a = input("Enter Number : ") print("Entered input's type is", a) b = int(a) print("Entered input's type is", b) print("Entered input's type is", type(b)) c = float(a) print("Entered input's type is", c) print("Entered input's type is", type(c)) d = complex(a) print("Entered input's type is", d) print("Entered input's type is", type(d))Output :
Enter Number : 4 Entered input's type is 4 Entered input's type is 4 Entered input's type is Entered input's type is 4.0 Entered input's type is Entered input's type is (4+0j) Entered input's type is
Python Print Function print()
Function for Displaying Output on Screen
अभी तक User के screen पर output दिखाने के लिए 'print()' function का इस्तेमाल किया गया था, लेकिन print() function के लिए एक से ज्यादा parameters होते है | जिनका इस्तेमाल एक से ज्यादा newline देना या file handling के लिए किया जाता है |
Regular Example for print() Function
a = 5 print("Value of a is", a) #Output : Value of a is 5Syntax for print() Function
print(value1,value2,...,valueN, sep="", end="\n", file=sys.stdout, flush=False)
Parameter :
value1,value2,...,valueN, :
यहाँ पर एक या एक से ज्यादा values दी जाती है | हर value को comma(,) से seperate किया जाता है |
sep=" " :
Optional. जब एक से ज्यादा values दी जाती है तो default 'sep' parameter द्वारा space( ) दिया जाता है | User चाहे तो 'sep' parameter पर कोई भी value दे सकता है |
end="\n" :
Optional. 'end' parameter पर '\n'(newline) default दिया जाता है | User चाहे तो 'end' parameter पर कोई भी value दे सकता है |
file=sys.stdout :
Optional. 'file' parameter पर 'sys.stdout'(print entered text on screen) default दिया जाता है | User चाहे तो 'file' parameter पर किसी भी file को open कर सकता है |
flush=False :
Optional. 'flush' parameter पर 'False' ये value default होती है | जब False दिया जाता है तब stream को flush नहीं किया जाता है या जब 'True' दिया जाता है तब stream को जबरन flush किया जाता है |
print() function null/None return करता है |
Example for print() Function with 'sep' Parameter Example पर '!!!!!' इस string से separate किया गया है |
Source Code :
print("Hello World", "Hello Friends", "Hello Maxon", sep="!!!!!")Output :
Hello World!!!!!Hello Friends!!!!!Hello Maxon
Example for print() Function with 'end' Parameter
Example में end पर '\n\n\n\n\n' इस string दिया गया है |
Source Code :
print("Hello World", end="\n\n\n\n\n") print("Hello Friends")
Output :
Hello World Hello Friends
Example for print() Function with 'file' Parameter
Example पर print() function के 'file' parameter द्वारा 'textfile.txt' इस file पर 'Hello World' ये string write किया गया है |
Source Code :
f = open("textfile.txt", "w") print("Hello World", file = f) f.close()textfile.txt
Hello World
Note : print() function में binary files पर operation नहीं किया जाता है | इसके बदले में write() function का इस्तेमाल किया जाता है |
अगर आपको यह पोस्ट 📑 (Python Input Output In Hindi)पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !