Lesson – 107 : Modules, Input અને Output in Python

Python એક શક્તિશાળી અને બહુમુખી પ્રોગ્રામિંગ ભાષા છે. પ્રોગ્રામિંગમાં Modules, Input (ઇનપુટ) અને Output (આઉટપુટ) બહુ મહત્વના વિષયો છે.

Modules, Input અને Output in Python


⭐ 1. Python Modules (મોડ્યુલ્સ)

મોડ્યુલ શું છે?

Python માં મોડ્યુલ એટલે કે એક એવી ફાઈલ જેમાં સંબંધિત functions, variables અને classesનો સેટ હોય છે.
મોડ્યુલ્સનો ઉપયોગ કોડને ફરી લખવાની જરૂરિયાત ઘટાડવા, કોડને ગોઠવેલ રાખવા અને પ્રોજેક્ટને સરળ બનાવે છે.

Module ના પ્રકાર
  1. Built-in Modules
    Python માં પહેલાથી હાજર છે.
    જેવા કે — math, random, datetime

  2. User-defined Modules
    આપણે પોતે બનાવી શકીએ છીએ.

મોડ્યુલ Import કરવાની રીત
import math
print(math.sqrt(25)) # Output: 5.0
મોડ્યુલમાંથી ચોક્કસ ફંક્શન ઇમ્પોર્ટ કરવું
from math import pi
print(pi)

⭐ 2. Input in Python (ઇનપુટ લેવાની પ્રક્રિયા)

Python માં user પાસેથી ડેટા મેળવવા માટે input() function નો ઉપયોગ થાય છે.

Example:
name = input("Enter your name: ")
print("Hello", name)
Input હંમેશા string રૂપમાં મળે છે

જો તમને integer જોઈએ હોય, તો type conversion કરવું પડે.

num = int(input("Enter a number: "))
print(num * 2)
Multiple inputs લેવી
a, b = input("Enter two numbers: ").split()
print(a, b)

⭐ 3. Output in Python (આઉટપુટ બતાવવી)

Python માં આઉટપુટ બતાવવા માટે print() function નો ઉપયોગ થાય છે.

Basic Output
print("Welcome to Python")
Multiple values print કરવી
x = 10
y = 20
print("Sum =", x + y)
Formatted Output

Python માં formatted output માટે f-string ખુબ ઉપયોગી છે.

name = "Jaydip"
age = 20
print(f"My name is {name} and I am {age} years old.")

Topic Explanation
Modules કોડને અલગ-અલગ ફાઈલોમાં વહેંચી તેને organization-friendly બનાવે છે
Input() User પાસેથી value લેવાની function
Output (print()) Screen પર પરિણામ બતાવવા માટે ઉપયોગ થાય છે
Formatted Output f-string દ્વારા attractive આઉટપુટ