python python tutorial in hindi python data type python variable python operators conditional statements in python python tuple

File Pointer

Table of Contents All Chapters 1. File Pointer 2. File Pointer Methods ┬а ┬а ┬а2.1. tell() Method ┬а ┬а ┬а2.2. seek() Method ┬а Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String Python List Python Tuple Python Set Python Dictionary Python Function Python Classes and Objects Python Inheritance Python Polymorphism Python Iterators Python Modules File Handling File Pointer Hamburger Toggle Menu Table of Contents 1. File Pointer 2. File Pointer Methods ┬а ┬а ┬а2.1. tell() Method ┬а ┬а ┬а2.2. seek() Method File Pointerr in Hindi What is File Pointer in Python File pointer рдПрдХ position рд╣реЛрддрд╛ рд╣реИ, рдЬреЛ рд╣рдореЗ рджрд┐рдЦрд╛рддрд╛ рд╣реИ рдХрд┐ рд╣рдо file рдореЗрдВ рдХрд┐рд╕ рдЬрдЧрд╣ рдкрд░ рд╣реИ, python рдореЗрдВ by default рдпреЗ pointer рдХрд┐рд╕реА file рдХреЗ starting (рдпрд╛рдирд┐ 0 index) рдкрд░ рд╣реЛрддрд╛ рд╣реИред File Pointer Methods python рдореЗрдВ file pointer рдХреЗ position рдХреЗ рд▓рд┐рдП f.tell() рдФрд░ f.seek() functions рдХрд╛ use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред tell() Method tell() method рд╣рдореЗ file pointer рдХрд╛ current position рдмрддрд╛рддрд╛ рд╣реИред рдЬрдм file рдХреЛ open рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рддреЛ pointer рдХрд╛ position 0 index (starting) рдкрд░ рд╣реЛрддрд╛ рд╣реИ, but рдЬрдм рд╣рдо file рдореЗрдВ рдХреБрдЫ read рдпрд╛ write рдХрд░рддреЗ рд╣реИ рддреЛ pointer move рд╣реЛ рдЬрд╛рддрд╛ рд╣реИ, рдРрд╕реЗ рдореЗрдВ рд╣рдо tell() method рдХрд╛ use рдХрд░рдХреЗ pointer рдХрд╛ current position рджреЗрдЦ рд╕рдХрддреЗ рд╣реИред ЁЯРН Example 1.py Copy to clipboard 1 2 3 4 f = open("demo.txt","r") print(f.read(5)) # first 5 characters read print("Pointer at:", f.tell()) # ab pointer position 5 pe hai f.close() seek() Method seek() method рдХрд╛ use рдХрд░рдХреЗ рд╣рдо pointer рдХреЛ рдХрд┐рд╕реА specific position рдкрд░ рд▓реЗ рдЬрд╛ рд╕рдХрддреЗ рд╣реИред рдЗрд╕рдореЗ 2 parameter рд╣реЛрддреЗ рд╣реИ- offset : рд╣рдореЗ pointer рдХреЛ file рдореЗрдВ рдХрд┐рддрдиреЗ bytes move рдХрд░рдирд╛ рд╣реИ рд╡реЛ argument (number) рд╣рдореЗ рдЗрд╕рдореЗ рджреЗрдВрдЧреЗред whence : рдпреЗ optional рд╣реЛрддрд╛ рд╣реИ рдЬрд┐рд╕рдХрд╛ by default value 0 рд╣реЛрддрд╛ рд╣реИ рдорддрд▓рдм pointer file рдореЗрдВ beginning рд╕реЗ move рд╣реЛрдЧрд╛ред рдЕрдЧрд░ рд╣рдо рдЗрд╕рдореЗ 1 рджреЗрдВрдЧреЗ рддреЛ pointer рдЕрдкрдиреЗ current position рд╕реЗ move рд╣реЛрдЧрд╛, рдФрд░ рдЕрдЧрд░ рд╣рдореЗ 2 рджреЗрдВрдЧреЗ рддреЛ pointer рдЙрд╕ file рдореЗрдВ end рд╕реЗ move рдХрд░реЗрдЧрд╛ред ЁЯРН Example 2.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # File content: "HelloWorld" (10 characters) # whence = 0 (beginning of file) with open("demo.txt", "r") as f: f.seek(3, 0) # start se 3 characters aage – index=3 print("seek(3,0) position:", f.tell()) print("read(4):", f.read(4)) # "loWo" # whence = 1 (current position) with open("demo.txt", "r") as f: print("read(5):", f.read(5)) # "Hello"; pointer now at 5 f.seek(2, 1) # current position (5) + 2 – index=7 print("seek(2,1) position:", f.tell()) print("read(2):", f.read(2)) # "rl" # whence = 2 (end of file) with open("demo.txt", "rb") as f: # binary mode recommended f.seek(-4, 2) # end se 4 bytes peeche – index=6 print("seek(-4,2) position:", f.tell()) print("read():", f.read()) # b"orld" рдЙрдореНрдореАрдж рдХрд░рддреЗ рд╣реИ рдХрд┐ рдЖрдкрдХреЛ File Pointer рдЕрдЪреНрдЫреЗ рд╕рдордЭ рдореЗ рдЖ рдЧрдпрд╛ рд╣реЛрдЧрд╛ рдпреЗ рдПрдХ File Handling рдХрд╛ topic рд╣реИред рдЕрдкрдиреЗ learning рдХреЛ continue рд░рдЦрдиреЗ рдХреЗ рд▓рд┐рдП next button рдкрд░ click рдХрд░реЗ, Previous Next Add a comment… Cancel Reply Logged in as Python Programming Hub. Edit your profile. Log out? Required fields are marked * Message*

python python tutorial in hindi python data type python variable python operators conditional statements in python python tuple

File Handling

Table of Contents All Chapters 1. File Handling 2. Types of File 3. open() and close() Methods 4. File Modes 5. Reading a File 6. Writing to a File 7. with Statement ┬а Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String Python List Python Tuple Python Set Python Dictionary Python Function Python Classes and Objects Python Inheritance Python Polymorphism Python Iterators Python Modules Hamburger Toggle Menu Table of Contents 1. File Handling 2. Types of File 3. open() and close() Methods 4. File Modes 5. Reading a File 6. Writing to a File 7. with Statement File Handling in Hindi What is File Handling in Python Python code рдХрд╛ use рдХрд░рдХреЗ рдЬрдм рд╣рдо files рдХреЛ create, read, write рдФрд░ update рдХрд░рддреЗ рд╣реИ рддреЛ рдЗрд╕реЗ file handling in python рдХрд╣рддреЗ рд╣реИред рдЬрдм рд╣рдореЗ data рдХреЛ permanent store рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИ рддреЛ рд╣рдо file handling рдХрд╛ use рдХрд░рддреЗ рд╣реИред Types of File 1.Text File : рдРрд╕реЗ files рдЬрд┐рд╕рдореЗ texts, numbers рд╣реЛрддреЗ рд╣реИ рдЙрдиреНрд╣реЗ text file рдХрд╣рддреЗ рд╣реИ, рдЗрди files рдХреЛ рд╣рдо read рдХрд░ рд╕рдХрддреЗ рд╣реИред рдЬреИрд╕реЗ : .txt, .csv, .log, 2. Binary File : images, videos, software executables рдЬреИрд╕реЗ files рдХреЛ binary file рдХрд╣рд╛ рдЬрд╛рддрд╛ рд╣реИ, рдпреЗ human-readable рдирд╣реАрдВ рд╣реЛрддреА рд╣реИред рдЬреИрд╕реЗ : .jpg, .mp4, .exe, How to open and close a file in Python open() : python рдореЗрдВ file рдХреЛ open рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП open() method рдХрд╛ use рдХрд░рддреЗ рд╣реИред close() : python рдореЗрдВ рдХрд┐рд╕реА open file рдХреЛ close рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП close() method рдХрд╛ use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред рдХреНрдпреЛрдВрдХрд┐ рдЬрдм file рдкрд░ рдХрд╛рдо рдЬреЛ рдЬрд╛рдП рддреЛ рдЙрд╕реЗ close рдХрд░ рджреЗрдирд╛ рдЪрд╛рд╣рд┐рдП рдЗрд╕рд╕реЗ рдпреЗ ensure рд╣реЛ рдЬрд╛рддрд╛ рд╣реИ рдХреА data properly save рд╣реЛ рдЧрдП рд╣реИ, рдФрд░ file close рдХрд░ рджреЗрдиреЗ рд╕реЗ memory free рднреА рд╣реЛ рдЬрд╛рддреА рд╣реИред File Modes in Python рдЬрдм рд╣рдо python code рд╕реЗ file рдХреЛ open рдХрд░рддреЗ рд╣реИ рддреЛ рд╣рдореЗ рдПрдХ mode рджреЗрдирд╛ рд╣реЛрддрд╛ рд╣реИ рдХреА рд╣рдо file рдХреЛ рдХрд┐рд╕рд▓рд┐рдП open рдХрд░ рд░рд╣реЗ рд╣реИ read рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, write рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдпрд╛ рдХрд┐рд╕реА рдФрд░ рдХрд╛рдо рдХреЗ рд▓рд┐рдП file рдХреЛ open рдХрд░ рд░рд╣реЗ рд╣реИред ┬а тАЬrтАЭ : рдЗрд╕реЗ read mode рдХрд╣рддреЗ рд╣реИ рдЕрдЧрд░ рд╣рдо рдЗрд╕ mode рдореЗрдВ file рдХреЛ open рдХрд░рддреЗ рд╣реИ рддреЛ рд╣рдо file рдХреЗ data рдХреЛ рд╕рд┐рд░реНрдл read (рдкреЭ) рд╣реА рдХрд░ рд╕рдХрддреЗ рд╣реИред тАЬwтАЭ : рдЗрд╕реЗ write mode рдХрд╣рддреЗ рд╣реИ рдЕрдЧрд░ рд╣рдо рдЗрд╕ mode рдореЗрдВ file рдХреЛ open рдХрд░рддреЗ рд╣реИ рддреЛ рдЙрд╕ file рдХрд╛ рд╕рд╛рд░рд╛ data overwrite рд╣реЛ рдЬрд╛рдПрдЧрд╛ рдорддрд▓рдм рдЙрд╕ file рдореЗрдВ рд╣рдо рдХреЛрдИ data рдбрд╛рд▓реЗрдВрдЧреЗ рддреЛ old data рдпреЗ рдЬрдЧрд╣ рдЕрдм new рд╡рд╛рд▓рд╛ data рджрд┐рдЦрд╛рдИ рджреЗрдЧрд╛ред but рд╣рдордиреЗ рдЬреЛ file write mode рдореЗрдВ open рдХрд┐рдпрд╛ рд╣реИ рдЕрдЧрд░ рд╡реЛ file exist рд╣реА рдирд╣реАрдВ рдХрд░рддрд╛ рд╣реИ рддреЛ write mode рдЙрд╕ name рдХрд╛ new file create рдХрд░ рджреЗрдЧрд╛ред тАЬaтАЭ : рдЗрд╕реЗ append mode рдХрд╣рддреЗ рд╣реИ рд╣рдо рдЗрд╕ mode рдореЗрдВ file рдХреЛ open рддрдм рдХрд░рддреЗ рд╣реИ рдЬрди рд╣рдореЗ рдЙрд╕ file рдХреЗ end рдореЗрдВ рдХреЛрдИ data рдбрд╛рд▓рдирд╛ рд╣реЛрддрд╛ рд╣реИред тАЬxтАЭ : рдЗрд╕реЗ exclusive mode рдХрд╣рддреЗ рд╣реИ рдЬрдм рд╣рдо рдЗрд╕ mode рдореЗрдВ file рдХреЛ open рдХрд░рддреЗ рд╣реИ рддреЛ рдЕрдЧрд░ рдЗрд╕ рдирд╛рдо рдХрд╛ file рдкрд╣рд▓реЗ рд╕реЗ рдореМрдЬреВрдж рд╣реИ рддреЛ рд╣рдореЗ error show рд╣реЛрдЧрд╛, рдФрд░ рдЕрдЧрд░ рдРрд╕рд╛ рдХреЛрдИ рднреА file рдкрд╣рд▓реЗ рд╕реЗ рдирд╣реАрдВ рд╣реИ рддреЛ exclusive mode рдЗрд╕ рдирд╛рдо рдХрд╛ new file create рдХрд░ рджреЗрдЧрд╛ред тАЬbтАЭ : рдЗрд╕реЗ binary mode рдХрд╣рддреЗ рд╣реИ рдЬрдм рд╣реИ binary file (рдорддрд▓рдм image, videos рд╡рд╛рд▓реА files) рдХреЛ open рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИ рддреЛ рд╣рдо binary mode рдХрд╛ use рдХрд░рддреЗ рд╣реИред тАЬw+тАЭ : рдЗрд╕реЗ write and read mode рдХрд╣рддреЗ рд╣реИ, рдЗрд╕ mode рдореЗрдВ file рдХреЛ open рдХрд░рдиреЗ рдкрд░ рд╣рдо read рдФрд░ write рджреЛрдиреЛрдВ рдХрд░ рд╕рдХрддреЗ рд╣реИ, рдЕрдЧрд░ рд╣рдордиреЗ рдЬреЛ file open рдХрд┐рдпрд╛ рд╣реИ рд╡реЛ рдЗрд╕реЗ рдирд╣реАрдВ рдорд┐рд▓рддрд╛ рддреЛ рдпреЗ new file create рдХрд░ рджреЗрддрд╛ рд╣реИред рдЗрд╕ mode рдореЗрдВ рдЬрдм рд╣рдо file рдореЗрдВ write рдХрд░рддреЗ рд╣реИ рддреЛ file рдХрд╛ data overwrite рд╣реЛ рдЬрд╛рддрд╛ рд╣реИред тАЬr+тАЭ : рдЗрд╕реЗ read and write mode рдХрд╣рддреЗ рд╣реИ, рдЗрд╕ mode рдореЗрдВ file рдХреЛ open рдХрд░рдиреЗ рдкрд░ рд╣рдо read рдФрд░ write рджреЛрдиреЛрдВ рдХрд░ рд╕рдХрддреЗ рд╣реИ, рдЕрдЧрд░ рд╣рдордиреЗ рдЬреЛ file open рдХрд┐рдпрд╛ рд╣реИ рд╡реЛ рдЗрд╕реЗ рдирд╣реАрдВ рдорд┐рд▓рддрд╛ рддреЛ рдпреЗ error рджреЗрддрд╛ рд╣реИред рдЗрд╕ mode рдореЗрдВ рдЬрдм рд╣рдо file рдореЗрдВ write рдХрд░рддреЗ рд╣реИ рддреЛ file рдХрд╛ data overwrite рд╣реЛ рдЬрд╛рддрд╛ рд╣реИред Reading a file Python рдореЗрдВ file рдХреЛ read рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП read(), readline() рдФрд░ readlines() methods рдХрд╛ use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред ┬а read() : рдпреЗ methods рдХрд┐рд╕реА file рдХрд╛ рд╕рд╛рд░рд╛ content рдПрдХ рд╕рд╛рде read рдХрд░рддрд╛ рд╣реИред┬а readlines() : рдпреЗ methods file рдореЗрдВ рд╕реЗ рд╕рд┐рд░реНрдл рдПрдХ line рдХреЛ рд╣реА read рдХрд░рддрд╛ рд╣реИред readlines() : рдпреЗ methods рдХрд┐рд╕реА file рдХреЗ рд╕рд╛рд░реЗ lines рдХреЛ рдПрдХ list рдХреЗ form рдореЗрдВ рд╣рдореЗ рджреЗрддрд╛ рд╣реИред ЁЯРН Example 1.py Copy to clipboard 1 2 3 4 5 6 f = open("demo.txt","r") print(f.read()) print(f.readline()) print(f.readlines()) f.close() Writing to a file рдХрд┐рд╕реА file рдореЗрдВ write рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП python рдореЗрдВ write() рдФрд░ writelines() methods рдХрд╛ use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред write() : рдЗрд╕ method рд╕реЗ file рдореЗрдВ рдПрдХ рдмрд╛рд░ рдореЗрдВ рдПрдХ рд╣реА line рд▓рд┐рдЦрд╛ рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред writelines() : рдЗрд╕ methods рд╕реЗ file рдореЗрдВ multiple lines рдПрдХ рд╕рд╛рде рд▓рд┐рдЦрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред ЁЯРН Example 2.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 #write() f = open("demo.txt","w") f.write("Python File Handling Examplen") f.write("Second line") #writelines() lines = ["Line 1n", "Line 2n", "Line 3n"] f = open("demo.txt","w") f.writelines(lines) f.close() тАЬwithтАЭ statement рдЕрдЧрд░ рд╣рдо file рдХреЛ with statement рдХреЗ рд╕рд╛рде open рдХрд░рддреЗ рд╣реИ рддреЛ рд╣рдореЗ file рдХреЛ close рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП close() рдХрд╛ use рдХрд░рдиреЗ рдХреА рдЬрд░реВрд░рдд рдирд╣реАрдВ рд╣реЛрддреА, file automatically close рд╣реЛ рдЬрд╛рддреА рд╣реИред ЁЯРН Example 3.py Copy to clipboard 1 2 3 with open("demo.txt","r") as f: data = f.read() print(data) рдЙрдореНрдореАрдж рдХрд░рддреЗ рд╣реИ рдХрд┐ рдЖрдкрдХреЛ File Handling рдЕрдЪреНрдЫреЗ рд╕рдордЭ рдореЗ рдЖ рдЧрдпрд╛ рд╣реЛрдЧрд╛ ред рдЕрдкрдиреЗ learning рдХреЛ continue рд░рдЦрдиреЗ рдХреЗ рд▓рд┐рдП next button рдкрд░ click рдХрд░реЗ, Previous Next Add a comment… Cancel Reply Logged in as Python Programming Hub. Edit your profile. Log out? Required fields are marked * Message*

python python tutorial in hindi python data type python variable python operators conditional statements in python python tuple

Python Modules

Table of Contents All Chapters 1. Modules in Python 2. Pre-defined Modules ┬а ┬а ┬а2.1. math ┬а ┬а ┬а2.2. random ┬а ┬а ┬а2.3. datetime 3. Creating a Modules 4. How to Import a Module 5. Aliasing ┬а Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String Python List Python Tuple Python Set Python Dictionary Python Function Python Classes and Objects Python Inheritance Python Polymorphism Python Iterators Hamburger Toggle Menu Table of Contents 1. Modules in Python 2. Pre-defined Modules ┬а ┬а ┬а2.1. math ┬а ┬а ┬а2.2. random ┬а ┬а ┬а2.3. datetime 3. Creating a Modules 4. How to Import a Module 5. Aliasing Python Modules in Hindi What is Modules in Python Modules рдПрдХ рдРрд╕реЗ python files рд╣реЛрддреЗ рд╣реИ рдЬрд┐рд╕рдореЗ organized and reusable code рд▓рд┐рдЦреЗ рд╣реЛрддреЗ рд╣реИред рдХрд┐рд╕реА module рдореЗрдВ basically Classes, Functions, Variables, etc. runnable рд╣реА рд╣реЛрддреЗ рд╣реИ, рдЬрд┐рдирдХреЛ рд╣рдо рдЕрдкрдиреЗ program рдореЗрдВ import рдХрд░рдХреЗ reuse рдХрд░ рд╕рдХрддреЗ рд╣реИред Pre-defined Modules Python рдореЗрдВ рдХрдИ рд╕рд╛рд░реЗ pre_defined modules рд╣реЛрддреЗ рд╣реИ рдЬрд┐рдирдХреЛ рд╣рдо simply рдЕрдкрдиреЗ program рдореЗрдВ import рдХрд░рдХреЗ use рдХрд░ рд╕рдХрддреЗ рд╣реИ, рдЬреИрд╕реЗ- math рдЗрд╕ module рдореЗрдВ рдмрд╣реБрдд рд╕реЗ mathematical functions рд╣реЛрддреЗ рд╣реИред ramdom рдЗрд╕ module рдХрд╛ use рдХрд░рдХреЗ рд╣рдо random numbers рдХреЛ generate рдХрд░ рд╕рдХрддреЗ рд╣реИред datetime рдЗрд╕ module рдХрд╛ use date рдФрд░ time рдХреЗ manipulation рдореЗрдВ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред Creating a Modules рдЬреИрд╕рд╛ рдХреА рд╣рдордиреЗ рдЕрднреА discus рдХрд┐рдпрд╛ рдХрд┐ Modules рдХреЗ python file рд╣реА рд╣реЛрддреЗ рд╣реИ рдЗрд╕рд▓рд┐рдП module рдХреЛ create рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╣рдореЗ рд╕рдмрд╕реЗ рдкрд╣рд▓реЗ рдПрдХ python file create рдХрд░рдирд╛ рд╣реЛрдЧрд╛ рдлрд┐рд░ рд╣рдо рдЙрд╕рдореЗ code рдХреЛ рд▓рд┐рдЦреЗрдВрдЧреЗ, рд╣рдо рдЬреИрд╕рд╛ рдЪрд╛рд╣реЗ рд╡реИрд╕рд╛ code рд▓рд┐рдЦрд╛ рд╕рдХрддреЗ рд╣реИ рдЬреИрд╕реЗ рдХрд┐ рдЕрдЧрд░ рд╣рдореЗ рдХреБрдЫ functions рдХреЛ рдЕрдкрдиреЗ program рдореЗрдВ рдмрд╛рд░-рдмрд╛рд░ use рдХрд░рдирд╛ рд╣реИ рддреЛ рд╣рдо рдЙрди рд╕рднреА functions рдХреА coding рдЗрд╕ module рд▓рд┐рдЦ рд╕рдХрддреЗ рд╣реИ рдлрд┐рд░ рд╣рдо рдЗрд╕ module рдХреЛ рдЕрдкрдиреЗ рдХрд┐рд╕реА рднреА program рдореЗрдВ import рдХрд░рдХреЗ рдЗрд╕рдореЗ рд▓рд┐рдЦреЗ рд╕рднреА functions рдХреЛ access рдХрд░ рд╕рдХрддреЗ рд╣реИред ЁЯРН Example 1.py Copy to clipboard 1 2 3 4 5 6 7 # my_module.py def greet(name): return f"Hello, {name}" def add(a, b): return a + b How to Import a Module рдХрд┐рд╕реА рднреА module рдХреЛ рдХрд┐рд╕реА рджреВрд╕рд░реЗ module рдпрд╛ рдлрд┐рд░ рдХрд┐рд╕реА script (program) рдореЗрдВ import рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП тАЬimportтАЭ statement рдХрд╛ use рдХрд░рддреЗ рд╣реИред рд╣рдо рдЪрд╛рд╣реЗ рддреЛ рдПрдХ module рдХреЗ рдХрд┐рд╕реА specific item рдХреЛ рднреА import рдХрд░ рд╕рдХрддреЗ рд╣реИред ЁЯРН Example 2.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 import my_module print(my_module.greet("Alice")) # Output: Hello, Alice print(my_module.add(5, 3)) # Output: 8 # Importing specific item from my_module import greet, add print(greet("Bob")) # Output: Hello, Bob print(add(2, 4)) # Output: 6 Aliasing рдХреЛрдИ module рдХреЛ import рдХрд░рдиреЗ рдХреЗ рдмрд╛рдж рдЙрд╕рдХреЗ items рдХреЛ use рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╣рдореЗ рдЙрд╕ module рдХреЗ рдирд╛рдо рдХреЛ рд▓рд┐рдЦрдирд╛ рд╣реЛрддрд╛ рд╣реИ but рдХрд┐рд╕реА module рдХрд╛ рдирд╛рдо рд╣рдореЗ рдмреЬрд╛ рд▓рдЧ рд░рд╣рд╛ рд╣реИ рдФрд░ рд╣рдо рдЪрд╛рд╣рддреЗ рд╣реИ рдХреА рдЙрд╕реЗ рдПрдХ рдЫреЛрдЯреЗ рд╕ nickname рджреЗрдХрд░ рдЙрд╕ module рдФрд░ рдЙрд╕рдХреЗ items рдХреЛ use рдХрд░реЗ рддреЛ рд╣рдо aliasing рдХрд░рддреЗ рд╣реИ, рдЗрд╕рдХреЗ рд▓рд┐рдП рд╣рдореЗ рд╕рд┐рд░реНрдл тАЬasтАЭ statement рдХрд╛ use рдХрд░рдирд╛ рд╣реЛрдЧрд╛ред ЁЯРН Example 3.py Copy to clipboard 1 2 3 4 5 6 7 8 import my_module as mm print(mm.greet("Charlie")) # Output: Hello, Charlie print(mm.add(10, 20)) # Output: 30 from my_module import greet as g print(g("Dave")) # Output: Hello, Dave рдЙрдореНрдореАрдж рдХрд░рддреЗ рд╣реИ рдХрд┐ рдЖрдкрдХреЛ Python Modules рдЕрдЪреНрдЫреЗ рд╕рдордЭ рдореЗ рдЖ рдЧрдпрд╛ рд╣реЛрдЧрд╛ ред рдЕрдкрдиреЗ learning рдХреЛ continue рд░рдЦрдиреЗ рдХреЗ рд▓рд┐рдП next button рдкрд░ click рдХрд░реЗ, Previous Next Add a comment… Cancel Reply Logged in as Python Programming Hub. Edit your profile. Log out? Required fields are marked * Message*

Scroll to Top