{"id":74,"date":"2025-10-21T04:33:00","date_gmt":"2025-10-21T04:33:00","guid":{"rendered":"https:\/\/codetypingpro.com\/?p=74"},"modified":"2025-12-17T07:47:45","modified_gmt":"2025-12-17T07:47:45","slug":"lesson-15-python-standard-libraries","status":"publish","type":"post","link":"https:\/\/codetypingpro.com\/?p=74","title":{"rendered":"Lesson 15: Python Standard Libraries"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\ud83c\udfaf <strong>Lesson Objective<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To learn how to use Python\u2019s <strong>standard libraries<\/strong>, which provide pre-built modules and functions for common tasks, making programming faster and easier.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde9 <strong>1. What Are Standard Libraries?<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python comes with a <strong>rich set of built-in modules<\/strong> known as the <strong>standard library<\/strong>.<br>They cover areas like <strong>mathematics, file handling, data processing, networking, and more<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 <strong>Example: Using the <code>math<\/code> module<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import math\n\nprint(math.sqrt(25))  # Square root\nprint(math.factorial(5))  # Factorial\nprint(math.pi)  # Value of Pi\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>5.0\n120\n3.141592653589793\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2699\ufe0f <strong>2. Commonly Used Standard Libraries<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Library<\/th><th>Purpose<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td><code>math<\/code><\/td><td>Mathematical operations<\/td><td><code>math.sqrt(16)<\/code><\/td><\/tr><tr><td><code>random<\/code><\/td><td>Generate random numbers<\/td><td><code>random.randint(1,10)<\/code><\/td><\/tr><tr><td><code>datetime<\/code><\/td><td>Handle dates and times<\/td><td><code>datetime.date.today()<\/code><\/td><\/tr><tr><td><code>os<\/code><\/td><td>Operating system functions<\/td><td><code>os.listdir()<\/code><\/td><\/tr><tr><td><code>sys<\/code><\/td><td>System-specific parameters<\/td><td><code>sys.version<\/code><\/td><\/tr><tr><td><code>json<\/code><\/td><td>JSON data handling<\/td><td><code>json.dumps({\"a\":1})<\/code><\/td><\/tr><tr><td><code>csv<\/code><\/td><td>CSV file handling<\/td><td><code>csv.reader(file)<\/code><\/td><\/tr><tr><td><code>re<\/code><\/td><td>Regular expressions<\/td><td><code>re.findall(r\"\\d+\", \"Age 25\")<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd04 <strong>3. Using the <code>random<\/code> Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\n\nprint(random.randint(1, 100))  # Random integer\nprint(random.choice(&#91;\"apple\", \"banana\", \"cherry\"]))  # Random element\nprint(random.shuffle(&#91;1, 2, 3, 4, 5]))  # Shuffle list\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddf0 <strong>4. Using the <code>datetime<\/code> Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime\n\ntoday = datetime.date.today()\nnow = datetime.datetime.now()\n\nprint(\"Today's Date:\", today)\nprint(\"Current Time:\", now)\nprint(\"Year:\", now.year, \"Month:\", now.month, \"Day:\", now.day)\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddf1 <strong>5. Using the <code>os<\/code> Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\n\nprint(\"Current Directory:\", os.getcwd())\nprint(\"Files in Directory:\", os.listdir())\n# Create a new folder\n# os.mkdir(\"NewFolder\")\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udee0\ufe0f <strong>6. Using the <code>sys<\/code> Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import sys\n\nprint(\"Python Version:\", sys.version)\nprint(\"Command-line Arguments:\", sys.argv)\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udce6 <strong>7. Using the <code>json<\/code> Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\n\ndata = {\"name\": \"Sameer\", \"age\": 25}\njson_data = json.dumps(data)  # Convert to JSON string\nprint(json_data)\n\nparsed_data = json.loads(json_data)  # Convert back to Python dict\nprint(parsed_data&#91;\"name\"])\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0d <strong>8. Using the <code>re<\/code> Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import re\n\ntext = \"My phone number is 9876543210.\"\npattern = r\"\\d+\"\n\nnumbers = re.findall(pattern, text)\nprint(\"Numbers found:\", numbers)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Numbers found: &#91;'9876543210']\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udf0d <strong>9. Real-Life Example \u2013 Random Password Generator<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\nimport string\n\ndef generate_password(length):\n    characters = string.ascii_letters + string.digits + string.punctuation\n    password = ''.join(random.choice(characters) for i in range(length))\n    return password\n\nprint(\"Generated Password:\", generate_password(12))<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud83c\udfaf Lesson Objective To learn how to use Python\u2019s standard libraries, which provide pre-built modules and functions for common tasks, making programming faster and easier. \ud83e\udde9 1. What Are Standard Libraries? Python comes with a rich set of built-in modules known as the standard library.They cover areas like mathematics, file handling, data processing, networking, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,1],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-python-easy-course-outline","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":1,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":75,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/75"}],"wp:attachment":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}