PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Python Standard Library Modules: math, random, datetime, os, sys (मानक लाइब्रेरी मॉड्यूल्स: math, random, datetime, os और sys) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Python's 'batteries-included' standard library provides foundational built-in modules including math, random, datetime, os, and sys. Mastering their core methods, domain edge cases, and OS-versus-interpreter boundaries is critical for both software development and competitive IT exams.
अध्याय सार: पायथन की मानक लाइब्रेरी में math, random, datetime, os और sys जैसे शक्तिशाली मॉड्यूल्स पहले से उपलब्ध हैं। इनके मुख्य फंक्शन्स, सीमा स्थितियों और ऑपरेटिंग सिस्टम बनाम इंटरप्रेटर अंतर को समझना परीक्षा और प्रोग्रामिंग दोनों के लिए अत्यंत महत्वपूर्ण है।
Python Standard Library Modules: math, random, datetime, os, sys: Detailed Notes & Architecture (मानक लाइब्रेरी मॉड्यूल्स: math, random, datetime, os और sys)
1. math Module: Real-Number Precision and Domain Rules (math मॉड्यूल: गणितीय गणना और डोमेन नियम)
[EN] The `math` module wraps C-library real-number floating-point routines including `sqrt()`, `pow()`, `fabs()`, `ceil()`, `floor()`, `factorial()`, `gcd()`, and constants `pi`, `e`, `inf`, and `nan`. Unlike Python 2 where `ceil`/`floor` returned floats, Python 3 `math.ceil()` and `math.floor()` return exact integers (`math.floor(-2.3) == -3`, `math.ceil(-2.3) == -2`). Domain violations such as `math.sqrt(-1)` or `math.factorial(-5)` raise `ValueError` (use `cmath` for complex roots). To avoid binary floating-point rounding bugs like `0.1 + 0.2 == 0.3` returning `False`, use `math.isclose(0.1 + 0.2, 0.3)`.
[HI] `math` मॉड्यूल में `sqrt()`, `ceil()`, `floor()`, `factorial()`, `gcd()`, और `pi`, `e`, `inf` जैसे स्थिरांक मिलते हैं। पायथन 3 में `math.floor(-2.3)` का मान `-3` और `math.ceil(-2.3)` का मान `-2` (पूर्णांक) होता है। ऋणात्मक संख्या का वर्गमूल `math.sqrt(-1)` लेने पर `ValueError` आता है (सम्मिश्र संख्याओं के लिए `cmath` उपयोग होता है)। फ्लोटिंग-पॉइंट राउंडिंग त्रुटियों से बचने के लिए `==` के स्थान पर `math.isclose()` का प्रयोग किया जाता है।
2. random Module: PRNG Mechanics and Sampling Methods (random मॉड्यूल: स्यूडो-रैंडम जनरेशन और सैंपलिंग)
[EN] Python's `random` module implements the Mersenne Twister deterministic pseudo-random number generator (PRNG), whose sequence can be reproduced identically via `random.seed(n)`. Be careful of endpoint inclusivity: `random.randint(a, b)` includes BOTH `a` and `b`, whereas `random.randrange(a, b)` excludes `b` just like `range()`. For sequences, `choice(seq)` picks one element, `choices(seq, k=n)` picks with replacement, `sample(seq, k)` picks `k` unique items without replacement, and `shuffle(lst)` mutates a list in place returning `None`. Because Mersenne Twister state can be predicted from observed outputs, always use the `secrets` module—not `random`—for passwords, OTPs, and cryptographic tokens.
[HI] `random` मॉड्यूल Mersenne Twister एल्गोरिदम का उपयोग करता है, जिसे `random.seed(n)` द्वारा दोहराने योग्य बनाया जा सकता है। `random.randint(1, 6)` में `1` और `6` दोनों शामिल होते हैं, जबकि `random.randrange(1, 6)` में `6` शामिल नहीं होता। सीक्वेंस के लिए `choice()` एक आइटम, `choices()` रिप्लेसमेंट के साथ `k` आइटम, `sample()` बिना रिप्लेसमेंट के `k` अलग आइटम चुनता है, और `shuffle()` लिस्ट को इन-प्लेस मिलाकर `None` लौटाता है। पासवर्ड या OTP जैसे सुरक्षा कार्यों के लिए `random` के बजाय `secrets` मॉड्यूल का उपयोग करना चाहिए।
3. datetime Module: Temporal Types, Formatting, and Parsing (datetime मॉड्यूल: दिनांक, समय, फॉर्मेटिंग और पार्सिंग)
[EN] The `datetime` module exposes immutable temporal classes: `date`, `time`, `datetime`, `timedelta`, and `timezone`. Current local timestamp is retrieved via `datetime.datetime.now()`, while subtracting two `date` or `datetime` instances yields a `timedelta` storing `.days` and `.seconds`. Two frequently tested string methods are `strftime(fmt)` (converts a datetime object into a formatted string, e.g., `'%Y-%m-%d'`) and `strptime(text, fmt)` (parses a string into a `datetime` object). Time objects also support comparison operators and arithmetic with `timedelta(days=7)`.
[HI] `datetime` मॉड्यूल में `date`, `time`, `datetime`, `timedelta` और `timezone` जैसे इम्यूटेबल क्लास शामिल हैं। `datetime.now()` वर्तमान समय देता है, और दो तिथियों को घटाने पर `timedelta` ऑब्जेक्ट मिलता है जिसमें `.days` और `.seconds` होते हैं। परीक्षा में अक्सर पूछे जाने वाले दो मेथड हैं: `strftime()` जो ऑब्जेक्ट को फॉर्मेटेड स्ट्रिंग में बदलता है, और `strptime()` जो स्ट्रिंग को पार्स करके `datetime` ऑब्जेक्ट बनाता है। तिथियों में दिन जोड़ने या घटाने के लिए `timedelta(days=7)` के साथ `+` या `-` प्रयुक्त होता है।
4. os vs sys Modules: OS Boundary vs Interpreter Boundary (os बनाम sys मॉड्यूल: ऑपरेटिंग सिस्टम बनाम इंटरप्रेटर सीमा)
[EN] Exam questions frequently contrast `os` and `sys`: `os` interfaces with the underlying operating system, while `sys` interacts with the Python interpreter runtime itself. `os` provides `os.getcwd()`, `os.chdir()`, `os.listdir()`, `os.makedirs(..., exist_ok=True)`, `os.remove()`, `os.environ`, and cross-platform path utilities in `os.path` (like `os.path.join` and `os.path.exists`). `sys` provides command-line arguments in `sys.argv` (where `sys.argv[0]` is always the script name), `sys.path` (module search path), `sys.version`, `sys.getsizeof()`, and `sys.exit(code)` (which raises `SystemExit`). Remember that `os.path` is a submodule for filesystem paths, whereas `sys.path` is a Python `list` of import search folders.
[HI] परीक्षा में `os` और `sys` का अंतर प्रमुख है: `os` ऑपरेटिंग सिस्टम (फाइल सिस्टम, फोल्डर, एनवायरनमेंट) से बात करता है, जबकि `sys` स्वयं पायथन इंटरप्रेटर से जुड़ा है। `os` में `os.getcwd()`, `os.listdir()`, `os.makedirs()`, `os.environ` और `os.path.join()` जैसे टूल्स होते हैं। `sys` में `sys.argv` (जिसमें `sys.argv[0]` स्क्रिप्ट का नाम होता है), `sys.path`, `sys.version`, `sys.getsizeof()` और `sys.exit()` होते हैं। विशेष ध्यान रखें कि `os.path` एक मॉड्यूल है जबकि `sys.path` डायरेक्टरी स्ट्रिंग्स की एक `list` है।
Syntax, Formula & Technical Example (Python Standard Library Modules: math, random, datetime, os, sys)
import math, random, datetime, os, sys
random.seed(7)
today = datetime.date(2026, 3, 15)
next_week = today + datetime.timedelta(days=7)
print("ceil(-2.3):", math.ceil(-2.3), "gcd:", math.gcd(24, 36))
print("roll:", random.randint(1, 6), "future:", next_week.strftime("%d-%m-%Y"))
print("cwd:", os.path.basename(os.getcwd()), "script:", sys.argv[0])
Python Standard Library Modules: math, random, datetime, os, sys Quick Reference & Comparison Table
| Standard Module | Primary Domain & Key Functions | Key Exam Fact |
|---|---|---|
| math | Real math: sqrt, ceil, floor, gcd, isclose | Domain errors raise ValueError; ceil/floor return int in Py3 |
| random | PRNG: randint, randrange, sample, shuffle | randint(a, b) includes b; shuffle() returns None in-place |
| datetime | Temporal: date, datetime, timedelta, strftime | strftime formats to str; strptime parses str to datetime |
| os & sys | os: getcwd, environ; sys: argv, path, exit | os.path is a module; sys.path is module search list |
Python Standard Library Modules: math, random, datetime, os, sys Top 20 Bilingual MCQs with Answers
Q1. What is the key difference between `random.randint(1, 10)` and `random.randrange(1, 10)`?
(`random.randint(1, 10)` और `random.randrange(1, 10)` के बीच मुख्य अंतर क्या है?)
(A) randint returns a float while randrange returns an int
(B) randint(1, 10) can return 10, whereas randrange(1, 10) stops at 9
(C) randint requires a step parameter while randrange does not
(D) randrange can return 10 while randint stops at 9
Correct Answer: (B)
[EN] randint(a, b) is inclusive of both endpoints [a, b], whereas randrange(a, b) follows Python slice rules [a, b).
[HI] randint(1, 10) में 1 और 10 दोनों शामिल होते हैं, जबकि randrange(1, 10) में ऊपरी सीमा 10 शामिल नहीं होती (केवल 1 से 9 तक)।
Q2. What does `random.shuffle(my_list)` return?
(`random.shuffle(my_list)` कॉल करने पर क्या लौटता है?)
(A) A tuple containing the shuffled items
(B) A brand-new shuffled copy of my_list
(C) The number of swaps performed
(D) None (it modifies my_list in place)
Correct Answer: (D)
[EN] Like list.sort(), random.shuffle() mutates the list directly in place and returns None.
[HI] random.shuffle() मूल लिस्ट को ही इन-प्लेस बदलता है और रिटर्न वैल्यू के रूप में `None` देता है।
Q3. What do `math.floor(-4.2)` and `math.ceil(-4.2)` return in Python 3?
(पायथन 3 में `math.floor(-4.2)` और `math.ceil(-4.2)` का क्रमशः क्या परिणाम होगा?)
(A) -4 and -4
(B) -5.0 and -4.0
(C) -5 and -4
(D) -4 and -5
Correct Answer: (C)
[EN] floor rounds toward negative infinity (-5), ceil rounds toward positive infinity (-4), and both return int in Python 3.
[HI] floor नीचे की ओर (-5) और ceil ऊपर की ओर (-4) पूर्णांक देता है।
Q4. In the `datetime` module, which method converts a formatted string like `'2026-11-11'` into a `datetime` object?
(`datetime` मॉड्यूल में `'2026-11-11'` जैसी स्ट्रिंग को `datetime` ऑब्जेक्ट में बदलने के लिए कौन-सा मेथड प्रयुक्त होता है?)
(A) timestamp()
(B) strptime()
(C) strftime()
(D) isoformat()
Correct Answer: (B)
[EN] strptime (string parse time) parses a date string according to a format string into a datetime object; strftime formats in reverse.
[HI] strptime() स्ट्रिंग को पार्स करके datetime ऑब्जेक्ट बनाता है, जबकि strftime() ऑब्जेक्ट को स्ट्रिंग में बदलता है।
Q5. What type of object is produced when subtracting `date(2026, 3, 20) - date(2026, 3, 10)`?
(`date(2026, 3, 20) - date(2026, 3, 10)` घटाने पर किस प्रकार का ऑब्जेक्ट प्राप्त होता है?)
(A) int
(B) datetime.datetime
(C) datetime.timedelta
(D) datetime.date
Correct Answer: (C)
[EN] Subtracting two date or datetime instances yields a `datetime.timedelta` representing the duration between them.
[HI] दो date ऑब्जेक्ट्स का अंतर हमेशा `datetime.timedelta` ऑब्जेक्ट के रूप में मिलता है।
Q6. When running `python quiz.py 10 20`, what does `sys.argv` contain?
(`python quiz.py 10 20` कमांड चलाने पर `sys.argv` में क्या होता है?)
(A) ['quiz.py', '10', '20']
(B) ['python', 'quiz.py', '10', '20']
(C) ['10', '20']
(D) [10, 20]
Correct Answer: (A)
[EN] sys.argv is a list of strings starting with the script filename at index 0, followed by command-line arguments as strings.
[HI] sys.argv एक स्ट्रिंग लिस्ट है जिसके इंडेक्स 0 पर स्क्रिप्ट नाम `'quiz.py'` और आगे स्ट्रिंग रूप में आर्ग्यूमेंट्स `'10', '20'` होते हैं।
Q7. Which standard library module should be used instead of `random` for generating secure password reset tokens or OTPs?
(सुरक्षित पासवर्ड रीसेट टोकन या OTP बनाने के लिए `random` के स्थान पर किस मानक मॉड्यूल का उपयोग करना चाहिए?)
(A) secrets
(B) uuid1
(C) hashlib
(D) math
Correct Answer: (A)
[EN] The `secrets` module (Python 3.6+) uses the OS's cryptographically strong random source unlike Mersenne Twister in `random`.
[HI] `secrets` मॉड्यूल (पायथन 3.6+) क्रिप्टोग्राफी की दृष्टि से सुरक्षित रैंडम नंबर जनरेट करता है।
Q8. What exception is raised when calling `math.sqrt(-9)`?
(`math.sqrt(-9)` कॉल करने पर कौन-सा एक्सेप्शन उत्पन्न होता है?)
(A) ArithmeticError
(B) ValueError
(C) TypeError
(D) ZeroDivisionError
Correct Answer: (B)
[EN] The math module operates strictly on real numbers and raises ValueError for out-of-domain inputs like negative square roots.
[HI] math मॉड्यूल केवल वास्तविक संख्याओं पर कार्य करता है, इसलिए ऋणात्मक मान पर ValueError देता है।
Q9. What is the difference between `random.sample(seq, 3)` and `random.choices(seq, k=3)`?
(`random.sample(seq, 3)` और `random.choices(seq, k=3)` में क्या अंतर है?)
(A) choices picks without replacement; sample picks with replacement
(B) sample picks without replacement (unique positions); choices picks with replacement (may repeat)
(C) Both always return unique items
(D) sample works only on integers; choices works on strings
Correct Answer: (B)
[EN] random.sample() performs sampling without replacement (raises ValueError if k > len(seq)), while random.choices() samples with replacement.
[HI] sample() बिना दोहराव (without replacement) के चयन करता है जबकि choices() दोहराव के साथ (with replacement) चयन कर सकता है।
Q10. Which function returns the memory size of a Python object in bytes?
(कौन-सा फंक्शन किसी पायथन ऑब्जेक्ट का मेमोरी आकार बाइट्स में लौटाता है?)
(A) os.stat()
(B) math.sizeof()
(C) sys.getsizeof()
(D) len()
Correct Answer: (C)
[EN] sys.getsizeof(obj) returns the shallow memory footprint of an object in bytes.
[HI] sys.getsizeof(obj) किसी पायथन ऑब्जेक्ट द्वारा ली गई मेमोरी बाइट्स में बताता है।
Q11. Which `os` function safely creates nested directories `a/b/c` even if parent folders `a` and `b` do not yet exist?
(यदि `a` और `b` फोल्डर पहले से न बने हों, तो `a/b/c` जैसे नेस्टेड फोल्डर बनाने के लिए `os` का कौन-सा फंक्शन प्रयुक्त होता है?)
(A) os.makedirs('a/b/c', exist_ok=True)
(B) sys.makedirs('a/b/c')
(C) os.mkdir('a/b/c')
(D) os.getcwd('a/b/c')
Correct Answer: (A)
[EN] os.mkdir() creates only a single leaf directory and fails if parents are missing, whereas os.makedirs() creates intermediate directories recursively.
[HI] os.mkdir() केवल एक फोल्डर बनाता है, जबकि os.makedirs() सभी आवश्यक मध्यवर्ती डायरेक्टरीज को क्रमिक रूप से बना देता है।
Q12. What does calling `random.seed(100)` before `random.randint(1, 50)` guarantee?
(`random.randint(1, 50)` से पहले `random.seed(100)` कॉल करने से क्या सुनिश्चित होता है?)
(A) Only numbers divisible by 100 are returned
(B) The exact same sequence of pseudo-random numbers is produced every time the program runs
(C) The numbers become truly hardware-random and non-repeatable
(D) The PRNG resets after each single call
Correct Answer: (B)
[EN] Setting a fixed seed initializes the Mersenne Twister internal state identically across executions, ensuring reproducibility.
[HI] निश्चित सीड सेट करने से स्यूडो-रैंडम जनरेटर की प्रारंभिक अवस्था समान हो जाती है और हर बार वही संख्या क्रम मिलता है।
Q13. Which dictionary inside the `os` module holds operating system environment variables?
(`os` मॉड्यूल के भीतर कौन-सा मैपिंग ऑब्जेक्ट ऑपरेटिंग सिस्टम के एनवायरनमेंट वेरिएबल्स को रखता है?)
(A) sys.env
(B) os.environ
(C) os.path
(D) os.system
Correct Answer: (B)
[EN] os.environ is a mapping object representing string environment variables like PATH and HOME.
[HI] os.environ ऑपरेटिंग सिस्टम के एनवायरनमेंट वेरिएबल्स को की-वैल्यू जोड़ों के रूप में रखता है।
Q14. What does calling `sys.exit(0)` internally do in Python?
(पायथन में `sys.exit(0)` कॉल करने पर आंतरिक रूप से क्या होता है?)
(A) Immediately kills the OS process bypassing finally blocks
(B) Raises a SystemExit exception so cleanup finally blocks and with statements still run
(C) Restarts the Python interpreter
(D) Clears all global variables and continues execution
Correct Answer: (B)
[EN] sys.exit() raises the SystemExit exception (inheriting from BaseException), allowing `finally` blocks and context managers to clean up before exit.
[HI] sys.exit() SystemExit एक्सेप्शन उत्पन्न करता है, जिससे प्रोग्राम बंद होने से पहले `finally` और `with` ब्लॉक अपना क्लीनअप पूरा कर पाते हैं।
Q15. What is the output of: import math print(math.isclose(0.1 + 0.2, 0.3))
(कोड का आउटपुट क्या होगा: import math print(math.isclose(0.1 + 0.2, 0.3)))
(A) 0.3
(B) True
(C) False
(D) ValueError
Correct Answer: (B)
[EN] While `0.1 + 0.2 == 0.3` is False due to IEEE 754 representation, `math.isclose()` checks relative tolerance and returns True.
[HI] IEEE 754 फ्लोटिंग-पॉइंट त्रुटि के बावजूद `math.isclose()` सन्निकट तुलना करके `True` लौटाता है।
Q16. Which statement is NOT true about Python's math, random, datetime, os, and sys modules?
(math, random, datetime, os और sys मॉड्यूल्स के बारे में निम्न में से कौन-सा कथन सत्य नहीं है?)
(A) math.factorial(5) returns 120
(B) os.path and sys.path refer to the exact same object in memory
(C) os.getcwd() returns the current working directory string
(D) datetime.datetime.now() returns the current local date and time
Correct Answer: (B)
[EN] os.path is a module providing filesystem path functions (like join, exists), whereas sys.path is a list of module import search directories.
[HI] os.path एक मॉड्यूल है जबकि sys.path डायरेक्टरीज की एक लिस्ट है; दोनों एक ही ऑब्जेक्ट नहीं हैं।
Q17. Within Python Standard Library Modules: math, random, datetime, os, sys, which standard module directly maps to: "Real math: sqrt, ceil, floor, gcd, isclose"?
(Python Standard Library Modules: math, random, datetime, os, sys में कौन सा Standard Module सीधे "Real math: sqrt, ceil, floor, gcd, isclose" से संबंधित है?)
(A) os & sys
(B) math
(C) datetime
(D) random
Correct Answer: (B)
[EN] In Python Standard Library Modules: math, random, datetime, os, sys, 'math' handles 'Real math: sqrt, ceil, floor, gcd, isclose' (Domain errors raise ValueError; ceil/floor return int in Py3).
[HI] Python Standard Library Modules: math, random, datetime, os, sys में 'math' का कार्य/विवरण 'Real math: sqrt, ceil, floor, gcd, isclose' (Domain errors raise ValueError; ceil/floor return int in Py3) है।
Q18. Which option accurately describes 'random' in Python Standard Library Modules: math, random, datetime, os, sys?
(Python Standard Library Modules: math, random, datetime, os, sys के संदर्भ में 'random' की सही विशेषता कौन सी है?)
(A) os: getcwd, environ; sys: argv, path, exit
(B) PRNG: randint, randrange, sample, shuffle
(C) Real math: sqrt, ceil, floor, gcd, isclose
(D) Temporal: date, datetime, timedelta, strftime
Correct Answer: (B)
[EN] 'random' provides 'PRNG: randint, randrange, sample, shuffle' — key point: randint(a, b) includes b; shuffle() returns None in-place.
[HI] 'random' का मुख्य विवरण 'PRNG: randint, randrange, sample, shuffle' है (randint(a, b) includes b; shuffle() returns None in-place)।
Q19. In Python Standard Library Modules: math, random, datetime, os, sys, identify the correct parameter for the specification: "Temporal: date, datetime, timedelta, strftime".
(Python Standard Library Modules: math, random, datetime, os, sys में "Temporal: date, datetime, timedelta, strftime" विवरण किस विकल्प के लिए सही है?)
(A) random
(B) os & sys
(C) math
(D) datetime
Correct Answer: (D)
[EN] 'datetime' corresponds to 'Temporal: date, datetime, timedelta, strftime' (strftime formats to str; strptime parses str to datetime).
[HI] 'datetime' का संबंध 'Temporal: date, datetime, timedelta, strftime' (strftime formats to str; strptime parses str to datetime) से है।
Q20. Considering Python Standard Library Modules: math, random, datetime, os, sys, what key behavior defines 'os & sys'?
(Python Standard Library Modules: math, random, datetime, os, sys में 'os & sys' की मुख्य भूमिका या मान क्या है?)
(A) Temporal: date, datetime, timedelta, strftime
(B) os: getcwd, environ; sys: argv, path, exit
(C) Real math: sqrt, ceil, floor, gcd, isclose
(D) PRNG: randint, randrange, sample, shuffle
Correct Answer: (B)
[EN] 'os & sys' represents 'os: getcwd, environ; sys: argv, path, exit' (os.path is a module; sys.path is module search list).
[HI] 'os & sys' का अर्थ/मान 'os: getcwd, environ; sys: argv, path, exit' है (os.path is a module; sys.path is module search list)।
Python Standard Library Modules: math, random, datetime, os, sys — Exam FAQs
Q1: What is the conceptual difference between the `os` module and the `sys` module?
`os` मॉड्यूल और `sys` मॉड्यूल के बीच सैद्धांतिक अंतर क्या है?
[EN] `os` acts as an interface to the underlying Operating System (directories, files, environment variables, process IDs), whereas `sys` acts as an interface to the Python interpreter runtime itself (CLI arguments `sys.argv`, import paths `sys.path`, version, recursion limit, `sys.exit()`).
[HI] `os` मॉड्यूल ऑपरेटिंग सिस्टम (फाइलों, डायरेक्टरीज, एनवायरनमेंट वेरिएबल्स) से संवाद करता है, जबकि `sys` मॉड्यूल स्वयं पायथन इंटरप्रेटर (CLI आर्ग्यूमेंट `sys.argv`, `sys.path`, `sys.exit()`) से जुड़ा होता है।
Q2: Why did `random.sample([1, 2, 3], 5)` raise a `ValueError`?
`random.sample([1, 2, 3], 5)` चलाने पर `ValueError` क्यों आता है?
[EN] `random.sample(population, k)` picks `k` distinct positions without replacement. You cannot pick 5 unique items from a population of size 3; for sampling with replacement, use `random.choices([1, 2, 3], k=5)` instead.
[HI] `random.sample()` बिना दोहराव के तत्व चुनता है, इसलिए 3 तत्वों वाली लिस्ट से 5 अद्वितीय तत्व नहीं चुने जा सकते। दोहराव के साथ चुनने के लिए `random.choices()` उपयोग करें।
Q3: How do I remember the difference between `strftime()` and `strptime()` in exams?
परीक्षा में `strftime()` और `strptime()` के बीच का अंतर आसानी से कैसे याद रखें?
[EN] Notice the `f` vs `p`: `str` + `f` (format) + `time` formats a datetime object INTO a string, while `str` + `p` (parse) + `time` parses a string INTO a datetime object.
[HI] `f` और `p` अक्षरों पर ध्यान दें: `strftime` में `f` का अर्थ Format है (ऑब्जेक्ट को स्ट्रिंग में फॉर्मेट करना), जबकि `strptime` में `p` का अर्थ Parse है (स्ट्रिंग को पार्स कर datetime बनाना)।
Post a Comment
Post a Comment