{"id":437,"date":"2026-06-21T12:39:10","date_gmt":"2026-06-21T12:39:10","guid":{"rendered":"https:\/\/paknoteshub.online\/?page_id=437"},"modified":"2026-06-21T12:41:45","modified_gmt":"2026-06-21T12:41:45","slug":"python","status":"publish","type":"page","link":"https:\/\/paknoteshub.online\/?page_id=437","title":{"rendered":"Python"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"437\" class=\"elementor elementor-437\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6e3c730 e-flex e-con-boxed e-con e-parent\" data-id=\"6e3c730\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1874cb2 elementor-widget elementor-widget-html\" data-id=\"1874cb2\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t\t<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\"\/>\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\/>\n  <title>Python Programming \u2013 University Level \u2013 Pak Notes Hub<\/title>\n  <link href=\"https:\/\/fonts.googleapis.com\/css2?family=Inter:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap\" rel=\"stylesheet\"\/>\n  <style>\n    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n    :root {\n      --green:#1a7a4a; --green-dark:#145f38; --green-light:#e8f5ee;\n      --teal:#17a589; --accent:#f0b127; --dark:#1c2833; --mid:#566573;\n      --light:#f4f6f7; --code-bg:#f0f4f8; --code-border:#2e86c1;\n      --note-bg:#fef9e7; --note-border:#f0b127; --white:#ffffff;\n      --radius:10px; --shadow:0 4px 24px rgba(26,122,74,.10);\n    }\n    html { scroll-behavior:smooth; }\n    body { font-family:'Inter',sans-serif; background:#f2f6f3; color:var(--dark); line-height:1.7; font-size:15px; }\n\n    \/* NAV *\/\n    nav { position:sticky; top:0; z-index:100; background:var(--green-dark); padding:0 2rem; display:flex; align-items:center; justify-content:space-between; height:56px; box-shadow:0 2px 12px rgba(0,0,0,.25); }\n    .nav-brand { color:#fff; font-weight:700; font-size:1.05rem; }\n    .nav-brand span { color:#a9dfbf; }\n    .nav-links { display:flex; gap:1.2rem; }\n    .nav-links a { color:#d5f5e3; font-size:.85rem; font-weight:500; text-decoration:none; transition:color .2s; }\n    .nav-links a:hover { color:#fff; }\n\n    \/* HERO *\/\n    .hero { background:linear-gradient(135deg,var(--green) 0%,#145f38 60%,#0d4527 100%); padding:5rem 2rem 4rem; text-align:center; position:relative; overflow:hidden; }\n    .hero::before { content:'PY'; position:absolute; right:6%; top:50%; transform:translateY(-50%); font-size:9rem; font-family:'Fira Code',monospace; color:rgba(255,255,255,.06); font-weight:700; pointer-events:none; }\n    .hero-tag { display:inline-block; background:rgba(255,255,255,.12); color:#a9dfbf; font-size:.78rem; font-weight:600; letter-spacing:1.5px; text-transform:uppercase; padding:.35rem 1rem; border-radius:100px; margin-bottom:1.2rem; border:1px solid rgba(169,223,163,.3); }\n    .hero h1 { color:#fff; font-size:clamp(1.8rem,5vw,3rem); font-weight:700; line-height:1.15; margin-bottom:.8rem; }\n    .hero h1 span { color:#a9dfbf; }\n    .hero p { color:#d5f5e3; font-size:1.05rem; max-width:580px; margin:0 auto 2rem; }\n    .hero-pills { display:flex; flex-wrap:wrap; justify-content:center; gap:.7rem; }\n    .pill { background:rgba(255,255,255,.13); color:#e8f5ee; padding:.45rem 1.1rem; border-radius:100px; font-size:.82rem; font-weight:500; border:1px solid rgba(255,255,255,.18); }\n\n    \/* LAYOUT *\/\n    .page-wrap { max-width:940px; margin:0 auto; padding:2.5rem 1.5rem 4rem; display:grid; grid-template-columns:235px 1fr; gap:2.5rem; align-items:start; }\n\n    \/* SIDEBAR *\/\n    .sidebar { position:sticky; top:72px; background:var(--white); border-radius:var(--radius); box-shadow:var(--shadow); overflow:hidden; }\n    .sidebar-title { background:var(--green); color:#fff; font-size:.75rem; font-weight:700; letter-spacing:1.2px; text-transform:uppercase; padding:.85rem 1.1rem; }\n    .toc-list { list-style:none; padding:.5rem 0; max-height:calc(100vh - 130px); overflow-y:auto; }\n    .toc-list li a { display:flex; align-items:center; gap:.55rem; padding:.4rem 1.1rem; color:var(--mid); font-size:.81rem; font-weight:500; text-decoration:none; transition:all .18s; border-left:3px solid transparent; }\n    .toc-list li a:hover,.toc-list li a.active { color:var(--green); background:var(--green-light); border-left-color:var(--green); }\n    .toc-num { display:inline-flex; align-items:center; justify-content:center; min-width:20px; height:20px; border-radius:4px; background:var(--green-light); color:var(--green); font-size:.7rem; font-weight:700; flex-shrink:0; }\n    .toc-list li a.active .toc-num { background:var(--green); color:#fff; }\n\n    \/* UNIT CARD *\/\n    .unit { background:var(--white); border-radius:var(--radius); box-shadow:var(--shadow); margin-bottom:2.5rem; overflow:hidden; scroll-margin-top:72px; }\n    .unit-header { background:linear-gradient(100deg,var(--green) 0%,#1d9560 100%); padding:1.4rem 1.8rem; }\n    .unit-num-badge { background:rgba(255,255,255,.18); color:#a9dfbf; font-size:.72rem; font-weight:700; letter-spacing:1px; text-transform:uppercase; padding:.3rem .75rem; border-radius:100px; }\n    .unit-header h2 { color:#fff; font-size:1.25rem; font-weight:700; line-height:1.25; margin-top:.35rem; }\n    .unit-header p { color:#c8f0d8; font-size:.85rem; margin-top:.2rem; }\n    .unit-body { padding:1.8rem; }\n\n    \/* HEADINGS & TEXT *\/\n    .unit-body h3 { font-size:1rem; font-weight:700; color:var(--green); margin:1.6rem 0 .7rem; padding-left:.85rem; border-left:3px solid var(--green); line-height:1.3; }\n    .unit-body h3:first-child { margin-top:0; }\n    .unit-body p { color:var(--dark); margin-bottom:.7rem; }\n    .unit-body ul { list-style:none; padding:0; margin:.5rem 0 1rem; }\n    .unit-body ul li { padding:.3rem 0 .3rem 1.5rem; position:relative; color:var(--dark); font-size:.93rem; }\n    .unit-body ul li::before { content:'\u27a4'; position:absolute; left:0; color:var(--teal); font-size:.75rem; top:.45rem; }\n    .unit-body code, .icode { font-family:'Fira Code',monospace; background:#eef2f5; color:#1a5276; padding:.1rem .4rem; border-radius:4px; font-size:.85em; }\n\n    \/* CODE BLOCK *\/\n    .code-block { background:var(--code-bg); border-left:4px solid var(--code-border); border-radius:6px; padding:1.1rem 1.3rem; margin:.9rem 0 1rem; overflow-x:auto; }\n    .code-block pre { font-family:'Fira Code',monospace; font-size:.83rem; color:#1a3a54; line-height:1.75; white-space:pre; }\n    .cm { color:#7f8c8d; } .kw { color:#1a5276; font-weight:600; } .st { color:#1e8449; }\n\n    \/* TABLES *\/\n    .data-table { width:100%; border-collapse:collapse; margin:.9rem 0 1.2rem; font-size:.87rem; border-radius:8px; overflow:hidden; box-shadow:0 1px 6px rgba(0,0,0,.06); }\n    .data-table thead th { background:var(--green); color:#fff; padding:.7rem 1rem; text-align:left; font-weight:600; font-size:.82rem; }\n    .data-table tbody tr:nth-child(even) { background:var(--green-light); }\n    .data-table tbody tr:hover { background:#d4efdf; }\n    .data-table td { padding:.6rem 1rem; border-bottom:1px solid #dce8e0; vertical-align:top; }\n    .data-table td:first-child { font-weight:600; color:var(--green-dark); }\n\n    \/* BOXES *\/\n    .info-box { background:var(--note-bg); border:1px solid var(--note-border); border-radius:7px; padding:.85rem 1.1rem; margin:.9rem 0; font-size:.88rem; line-height:1.6; color:#7d6608; display:flex; align-items:flex-start; gap:.7rem; }\n    .practice { background:var(--green-light); border:1.5px dashed var(--green); border-radius:8px; padding:.85rem 1.1rem; margin-top:1.4rem; color:var(--green-dark); font-size:.88rem; font-weight:500; }\n\n    \/* FEATURE GRID *\/\n    .feature-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(210px,1fr)); gap:.6rem; margin:.9rem 0 1.2rem; }\n    .feature-item { background:var(--green-light); border-radius:7px; padding:.6rem .9rem; font-size:.85rem; display:flex; align-items:center; gap:.5rem; color:var(--green-dark); border:1px solid #a2d9b5; font-weight:500; }\n\n    \/* CONCEPT GRID (cards) *\/\n    .concept-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:.8rem; margin:.9rem 0 1.2rem; }\n    .concept-card { background:var(--green-light); border:1px solid #a2d9b5; border-radius:8px; padding:.85rem 1rem; }\n    .concept-card .concept-name { font-weight:700; color:var(--green); font-size:.92rem; margin-bottom:.3rem; }\n    .concept-card .concept-rule { font-size:.8rem; color:var(--mid); }\n\n    \/* TOC CARD *\/\n    #toc-section { background:var(--white); border-radius:var(--radius); box-shadow:var(--shadow); margin-bottom:2.5rem; overflow:hidden; }\n    .toc-card-header { background:linear-gradient(100deg,var(--green) 0%,#1d9560 100%); padding:1.2rem 1.8rem; }\n    .toc-card-header h2 { color:#fff; font-size:1.2rem; font-weight:700; }\n    .toc-card-body { padding:1.4rem 1.8rem; }\n    .toc-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(250px,1fr)); gap:.6rem; }\n    .toc-item { background:var(--light); border-radius:7px; padding:.65rem 1rem; display:flex; align-items:center; gap:.75rem; text-decoration:none; color:var(--dark); font-size:.86rem; font-weight:500; border:1px solid #d5e5db; transition:all .18s; }\n    .toc-item:hover { background:var(--green-light); border-color:var(--green); color:var(--green); transform:translateY(-1px); }\n    .toc-badge { background:var(--green); color:#fff; font-size:.7rem; font-weight:700; min-width:22px; height:22px; border-radius:5px; display:inline-flex; align-items:center; justify-content:center; flex-shrink:0; }\n\n    \/* CONGRATS *\/\n    .congrats { background:linear-gradient(135deg,var(--green) 0%,#145f38 100%); border-radius:var(--radius); padding:2.5rem 2rem; text-align:center; color:#fff; margin-bottom:2.5rem; box-shadow:var(--shadow); }\n    .congrats h2 { font-size:1.8rem; margin-bottom:.5rem; }\n    .congrats p { color:#d5f5e3; font-size:1rem; }\n\n    \/* PROGRESS + BACK TOP *\/\n    .progress-bar { position:fixed; top:0; left:0; height:3px; background:var(--accent); z-index:200; transition:width .1s linear; width:0%; }\n    #back-top { position:fixed; bottom:2rem; right:2rem; background:var(--green); color:#fff; width:42px; height:42px; border-radius:50%; border:none; cursor:pointer; font-size:1.1rem; box-shadow:0 4px 14px rgba(26,122,74,.35); display:flex; align-items:center; justify-content:center; opacity:0; transition:opacity .25s,transform .25s; pointer-events:none; }\n    #back-top.visible { opacity:1; pointer-events:auto; }\n    #back-top:hover { transform:translateY(-2px); }\n\n    @media(max-width:720px){ .page-wrap{grid-template-columns:1fr;} .sidebar{position:static;display:none;} .hero::before{display:none;} nav .nav-links{display:none;} }\n  <\/style>\n<\/head>\n<body>\n\n<div class=\"progress-bar\" id=\"progress\"><\/div>\n\n<nav>\n  <div class=\"nav-brand\">Pak <span>Notes Hub<\/span><\/div>\n  <div class=\"nav-links\">\n    <a href=\"#toc-section\">Course Outline<\/a>\n    <a href=\"#unit-1\">Start Learning<\/a>\n    <a href=\"#unit-10\">Functions<\/a>\n    <a href=\"#unit-14\">OOP &amp; Project<\/a>\n  <\/div>\n<\/nav>\n\n<section class=\"hero\">\n  <div class=\"hero-tag\">\ud83d\udc0d University Level \u2014 BS CS \/ BS IT<\/div>\n  <h1>Python Programming<br\/><span>Complete Notes<\/span><\/h1>\n  <p>Variables to OOP \u00b7 Data Structures \u00b7 File &amp; Exception Handling \u2014 All in Easy English<\/p>\n  <div class=\"hero-pills\">\n    <span class=\"pill\">\ud83d\udc0d 15 Units<\/span>\n    <span class=\"pill\">\ud83c\udf93 University Level<\/span>\n    <span class=\"pill\">\ud83d\udcbb Code Examples<\/span>\n    <span class=\"pill\">\ud83d\udcdd Practice Tasks<\/span>\n    <span class=\"pill\">\ud83d\ude80 Final Project<\/span>\n  <\/div>\n<\/section>\n\n<div class=\"page-wrap\">\n\n  <!-- SIDEBAR -->\n  <aside class=\"sidebar\">\n    <div class=\"sidebar-title\">\ud83d\udccb Course Contents<\/div>\n    <ul class=\"toc-list\" id=\"toc-nav\">\n      <li><a href=\"#toc-section\"><span class=\"toc-num\">\ud83d\udccb<\/span> Contents<\/a><\/li>\n      <li><a href=\"#unit-1\"><span class=\"toc-num\">1<\/span> Intro to Python<\/a><\/li>\n      <li><a href=\"#unit-2\"><span class=\"toc-num\">2<\/span> Variables &amp; Data Types<\/a><\/li>\n      <li><a href=\"#unit-3\"><span class=\"toc-num\">3<\/span> Operators<\/a><\/li>\n      <li><a href=\"#unit-4\"><span class=\"toc-num\">4<\/span> Input \/ Output<\/a><\/li>\n      <li><a href=\"#unit-5\"><span class=\"toc-num\">5<\/span> Decision Making<\/a><\/li>\n      <li><a href=\"#unit-6\"><span class=\"toc-num\">6<\/span> Loops<\/a><\/li>\n      <li><a href=\"#unit-7\"><span class=\"toc-num\">7<\/span> Strings<\/a><\/li>\n      <li><a href=\"#unit-8\"><span class=\"toc-num\">8<\/span> Lists &amp; Tuples<\/a><\/li>\n      <li><a href=\"#unit-9\"><span class=\"toc-num\">9<\/span> Dictionaries &amp; Sets<\/a><\/li>\n      <li><a href=\"#unit-10\"><span class=\"toc-num\">10<\/span> Functions &amp; Scope<\/a><\/li>\n      <li><a href=\"#unit-11\"><span class=\"toc-num\">11<\/span> Lambda &amp; Comprehensions<\/a><\/li>\n      <li><a href=\"#unit-12\"><span class=\"toc-num\">12<\/span> Exception Handling<\/a><\/li>\n      <li><a href=\"#unit-13\"><span class=\"toc-num\">13<\/span> File Handling<\/a><\/li>\n      <li><a href=\"#unit-14\"><span class=\"toc-num\">14<\/span> OOP in Python<\/a><\/li>\n      <li><a href=\"#unit-15\"><span class=\"toc-num\">15<\/span> Modules &amp; Project<\/a><\/li>\n    <\/ul>\n  <\/aside>\n\n  <main>\n\n    <!-- TOC CARD -->\n    <div id=\"toc-section\">\n      <div class=\"toc-card-header\"><h2>\ud83d\udccb Table of Contents \u2014 15 Units<\/h2><\/div>\n      <div class=\"toc-card-body\">\n        <div class=\"toc-grid\">\n          <a class=\"toc-item\" href=\"#unit-1\"><span class=\"toc-badge\">1<\/span> Introduction to Python<\/a>\n          <a class=\"toc-item\" href=\"#unit-2\"><span class=\"toc-badge\">2<\/span> Variables, Data Types &amp; Casting<\/a>\n          <a class=\"toc-item\" href=\"#unit-3\"><span class=\"toc-badge\">3<\/span> Operators &amp; Expressions<\/a>\n          <a class=\"toc-item\" href=\"#unit-4\"><span class=\"toc-badge\">4<\/span> Input, Output &amp; Formatting<\/a>\n          <a class=\"toc-item\" href=\"#unit-5\"><span class=\"toc-badge\">5<\/span> Decision Making (if-elif-else)<\/a>\n          <a class=\"toc-item\" href=\"#unit-6\"><span class=\"toc-badge\">6<\/span> Loops \u2014 for &amp; while<\/a>\n          <a class=\"toc-item\" href=\"#unit-7\"><span class=\"toc-badge\">7<\/span> Strings &amp; String Methods<\/a>\n          <a class=\"toc-item\" href=\"#unit-8\"><span class=\"toc-badge\">8<\/span> Lists &amp; Tuples<\/a>\n          <a class=\"toc-item\" href=\"#unit-9\"><span class=\"toc-badge\">9<\/span> Dictionaries &amp; Sets<\/a>\n          <a class=\"toc-item\" href=\"#unit-10\"><span class=\"toc-badge\">10<\/span> Functions &amp; Scope<\/a>\n          <a class=\"toc-item\" href=\"#unit-11\"><span class=\"toc-badge\">11<\/span> Lambda, Map, Filter &amp; Comprehensions<\/a>\n          <a class=\"toc-item\" href=\"#unit-12\"><span class=\"toc-badge\">12<\/span> Exception Handling<\/a>\n          <a class=\"toc-item\" href=\"#unit-13\"><span class=\"toc-badge\">13<\/span> File Handling<\/a>\n          <a class=\"toc-item\" href=\"#unit-14\"><span class=\"toc-badge\">14<\/span> Object-Oriented Programming<\/a>\n          <a class=\"toc-item\" href=\"#unit-15\"><span class=\"toc-badge\">15<\/span> Modules &amp; Final Project<\/a>\n        <\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 1 -->\n    <div class=\"unit\" id=\"unit-1\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 1<\/span>\n        <h2>Introduction to Python<\/h2>\n        <p>What is Python and why is it the world's most popular language?<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is Python?<\/h3>\n        <p><strong>Python<\/strong> is a high-level, general-purpose, interpreted programming language created by <strong>Guido van Rossum<\/strong> and first released in 1991. It is famous for its clean, simple syntax that reads almost like plain English, making it one of the easiest languages for beginners to learn.<\/p>\n        <div class=\"info-box\">\ud83d\udca1 Python is named after the British comedy show \"Monty Python's Flying Circus\" \u2014 not the snake! Guido van Rossum was a fan of the show while creating the language.<\/div>\n\n        <h3>Key Features of Python<\/h3>\n        <div class=\"feature-grid\">\n          <div class=\"feature-item\">\u2705 Easy to Read &amp; Write<\/div>\n          <div class=\"feature-item\">\u2699\ufe0f Interpreted Language<\/div>\n          <div class=\"feature-item\">\ud83d\udd04 Dynamically Typed<\/div>\n          <div class=\"feature-item\">\ud83e\udde9 Object-Oriented<\/div>\n          <div class=\"feature-item\">\ud83c\udd93 Free &amp; Open Source<\/div>\n          <div class=\"feature-item\">\ud83d\udcda Huge Standard Library<\/div>\n          <div class=\"feature-item\">\ud83d\udcbb Cross-Platform<\/div>\n          <div class=\"feature-item\">\ud83c\udf0d Large Community Support<\/div>\n        <\/div>\n\n        <h3>Compiled vs Interpreted Languages<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Feature<\/th><th>Compiled (C, C++)<\/th><th>Interpreted (Python)<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Execution<\/td><td>Converted to machine code before running<\/td><td>Executed line-by-line by an interpreter<\/td><\/tr>\n            <tr><td>Speed<\/td><td>Generally faster<\/td><td>Generally slower<\/td><\/tr>\n            <tr><td>Errors<\/td><td>Shown only after full compilation<\/td><td>Shown immediately, line by line<\/td><\/tr>\n            <tr><td>Portability<\/td><td>Needs recompiling per OS<\/td><td>Same code runs anywhere Python is installed<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Applications of Python<\/h3>\n        <ul>\n          <li><strong>Web Development<\/strong> \u2014 Django, Flask frameworks<\/li>\n          <li><strong>Data Science &amp; Machine Learning<\/strong> \u2014 NumPy, Pandas, TensorFlow<\/li>\n          <li><strong>Automation &amp; Scripting<\/strong> \u2014 automating repetitive tasks<\/li>\n          <li><strong>Game Development<\/strong> \u2014 Pygame library<\/li>\n          <li><strong>Desktop GUI Apps<\/strong> \u2014 Tkinter, PyQt<\/li>\n          <li><strong>Cybersecurity<\/strong> \u2014 writing security &amp; pentesting tools<\/li>\n          <li><strong>Artificial Intelligence<\/strong> \u2014 the leading language for AI\/ML research<\/li>\n        <\/ul>\n\n        <h3>Writing Your First Python Program<\/h3>\n        <p>Python programs are saved with a <code>.py<\/code> extension and run using the Python interpreter.<\/p>\n        <div class=\"code-block\"><pre># This is a comment - Python ignores this line\nprint(\"Hello, World!\")\n\n# Output:\n# Hello, World!<\/pre><\/div>\n        <p>Run it from the terminal using:<\/p>\n        <div class=\"code-block\"><pre>python filename.py\n# or on some systems:\npython3 filename.py<\/pre><\/div>\n\n        <h3>Python Identifiers &amp; Keywords<\/h3>\n        <p>An <strong>identifier<\/strong> is the name given to variables, functions, and classes. Python has 35 <strong>reserved keywords<\/strong> that cannot be used as identifiers because they carry special meaning.<\/p>\n        <table class=\"data-table\">\n          <thead><tr><th>Category<\/th><th>Examples<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Values<\/td><td>True, False, None<\/td><\/tr>\n            <tr><td>Logical<\/td><td>and, or, not, in, is<\/td><\/tr>\n            <tr><td>Control Flow<\/td><td>if, elif, else, for, while, break, continue, pass<\/td><\/tr>\n            <tr><td>Functions \/ Classes<\/td><td>def, return, class, lambda<\/td><\/tr>\n            <tr><td>Modules<\/td><td>import, from, as<\/td><\/tr>\n            <tr><td>Error Handling<\/td><td>try, except, finally, raise, with<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Install Python on your computer, check the version using <code>python --version<\/code> in the terminal, and write a program that prints your name, roll number, and university on three separate lines.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 2 -->\n    <div class=\"unit\" id=\"unit-2\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 2<\/span>\n        <h2>Variables, Data Types &amp; Type Casting<\/h2>\n        <p>How Python stores and converts data.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is a Variable?<\/h3>\n        <p>A <strong>variable<\/strong> is a named location in memory used to store data. Unlike many other languages, Python variables do <strong>not<\/strong> require explicit type declaration \u2014 the type is decided automatically from the value assigned.<\/p>\n        <div class=\"code-block\"><pre>name = \"Ali\"        # string\nage = 20            # integer\ngpa = 3.75          # float\nis_pass = True      # boolean<\/pre><\/div>\n\n        <h3>Variable Naming Rules<\/h3>\n        <ul>\n          <li>Must start with a letter or underscore (_), not a digit<\/li>\n          <li>Can contain letters, digits, and underscores only<\/li>\n          <li>Case-sensitive \u2014 <code>age<\/code> and <code>Age<\/code> are different variables<\/li>\n          <li>Cannot be a Python keyword (e.g. <code>class<\/code>, <code>for<\/code>, <code>if<\/code>)<\/li>\n          <li>Should be descriptive \u2014 <code>student_name<\/code> is better than <code>x<\/code><\/li>\n        <\/ul>\n\n        <h3>Python Data Types<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Data Type<\/th><th>Example<\/th><th>Description<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>int<\/td><td>10, -5, 2024<\/td><td>Whole numbers (no decimal point)<\/td><\/tr>\n            <tr><td>float<\/td><td>3.14, -0.5<\/td><td>Numbers with a decimal point<\/td><\/tr>\n            <tr><td>str<\/td><td>\"Hello\"<\/td><td>Sequence of characters (text)<\/td><\/tr>\n            <tr><td>bool<\/td><td>True, False<\/td><td>Logical values<\/td><\/tr>\n            <tr><td>list<\/td><td>[1, 2, 3]<\/td><td>Ordered, changeable collection<\/td><\/tr>\n            <tr><td>tuple<\/td><td>(1, 2, 3)<\/td><td>Ordered, unchangeable collection<\/td><\/tr>\n            <tr><td>dict<\/td><td>{\"a\": 1}<\/td><td>Key-value pairs<\/td><\/tr>\n            <tr><td>set<\/td><td>{1, 2, 3}<\/td><td>Unordered collection of unique items<\/td><\/tr>\n            <tr><td>NoneType<\/td><td>None<\/td><td>Represents \"no value\"<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Checking Data Type \u2014 type()<\/h3>\n        <p>Use the built-in <code>type()<\/code> function to check the data type of any variable.<\/p>\n        <div class=\"code-block\"><pre>x = 25\ny = 3.14\nz = \"Python\"\n\nprint(type(x))   # &lt;class 'int'&gt;\nprint(type(y))   # &lt;class 'float'&gt;\nprint(type(z))   # &lt;class 'str'&gt;<\/pre><\/div>\n\n        <h3>Type Casting (Type Conversion)<\/h3>\n        <p><strong>Type casting<\/strong> means converting a value from one data type to another \u2014 either automatically (implicit) or manually (explicit).<\/p>\n        <table class=\"data-table\">\n          <thead><tr><th>Function<\/th><th>Converts To<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>int()<\/td><td>Integer<\/td><td>int(\"10\") \u2192 10<\/td><\/tr>\n            <tr><td>float()<\/td><td>Float<\/td><td>float(\"3.5\") \u2192 3.5<\/td><\/tr>\n            <tr><td>str()<\/td><td>String<\/td><td>str(25) \u2192 \"25\"<\/td><\/tr>\n            <tr><td>bool()<\/td><td>Boolean<\/td><td>bool(1) \u2192 True<\/td><\/tr>\n            <tr><td>list()<\/td><td>List<\/td><td>list(\"ab\") \u2192 ['a','b']<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>age = \"20\"             # string\nage = int(age)         # now an integer\nprint(age + 5)         # 25\n\nprice = 99\nprice_text = str(price)\nprint(\"Price: \" + price_text)   # Price: 99<\/pre><\/div>\n\n        <h3>Mutable vs Immutable Types<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Mutable (can be changed)<\/th><th>Immutable (cannot be changed)<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>list<\/td><td>int, float, bool<\/td><\/tr>\n            <tr><td>dict<\/td><td>str<\/td><\/tr>\n            <tr><td>set<\/td><td>tuple<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"info-box\">\ud83d\udca1 \"Immutable\" means once a value is created, it cannot be modified in place \u2014 a new object is created instead. Strings and tuples are immutable; lists and dictionaries are mutable.<\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Declare 5 variables of different data types (int, float, str, bool, list). Print each variable along with its type using <code>type()<\/code>.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 3 -->\n    <div class=\"unit\" id=\"unit-3\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 3<\/span>\n        <h2>Operators &amp; Expressions<\/h2>\n        <p>Arithmetic, comparison, logical and other operators.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>Arithmetic Operators<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Operator<\/th><th>Meaning<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>+<\/td><td>Addition<\/td><td>5 + 2<\/td><td>7<\/td><\/tr>\n            <tr><td>-<\/td><td>Subtraction<\/td><td>5 - 2<\/td><td>3<\/td><\/tr>\n            <tr><td>*<\/td><td>Multiplication<\/td><td>5 * 2<\/td><td>10<\/td><\/tr>\n            <tr><td>\/<\/td><td>Division (float)<\/td><td>5 \/ 2<\/td><td>2.5<\/td><\/tr>\n            <tr><td>\/\/<\/td><td>Floor Division<\/td><td>5 \/\/ 2<\/td><td>2<\/td><\/tr>\n            <tr><td>%<\/td><td>Modulus (remainder)<\/td><td>5 % 2<\/td><td>1<\/td><\/tr>\n            <tr><td>**<\/td><td>Exponent (power)<\/td><td>5 ** 2<\/td><td>25<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Comparison (Relational) Operators<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Operator<\/th><th>Meaning<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>==<\/td><td>Equal to<\/td><td>5 == 5 \u2192 True<\/td><\/tr>\n            <tr><td>!=<\/td><td>Not equal to<\/td><td>5 != 3 \u2192 True<\/td><\/tr>\n            <tr><td>&gt;<\/td><td>Greater than<\/td><td>5 &gt; 3 \u2192 True<\/td><\/tr>\n            <tr><td>&lt;<\/td><td>Less than<\/td><td>5 &lt; 3 \u2192 False<\/td><\/tr>\n            <tr><td>&gt;=<\/td><td>Greater or equal<\/td><td>5 &gt;= 5 \u2192 True<\/td><\/tr>\n            <tr><td>&lt;=<\/td><td>Less or equal<\/td><td>5 &lt;= 4 \u2192 False<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Logical Operators<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Operator<\/th><th>Meaning<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>and<\/td><td>True if both conditions are True<\/td><td>(5&gt;2) and (3&gt;1) \u2192 True<\/td><\/tr>\n            <tr><td>or<\/td><td>True if at least one condition is True<\/td><td>(5&gt;2) or (1&gt;3) \u2192 True<\/td><\/tr>\n            <tr><td>not<\/td><td>Reverses the result<\/td><td>not(5&gt;2) \u2192 False<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Assignment Operators<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Operator<\/th><th>Example<\/th><th>Same As<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>=<\/td><td>x = 5<\/td><td>x = 5<\/td><\/tr>\n            <tr><td>+=<\/td><td>x += 3<\/td><td>x = x + 3<\/td><\/tr>\n            <tr><td>-=<\/td><td>x -= 3<\/td><td>x = x - 3<\/td><\/tr>\n            <tr><td>*=<\/td><td>x *= 3<\/td><td>x = x * 3<\/td><\/tr>\n            <tr><td>\/\/=<\/td><td>x \/\/= 3<\/td><td>x = x \/\/ 3<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Membership &amp; Identity Operators<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Operator<\/th><th>Use<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>in<\/td><td>Checks if a value exists in a sequence<\/td><td>\"a\" in \"cat\" \u2192 True<\/td><\/tr>\n            <tr><td>not in<\/td><td>Checks if a value does not exist<\/td><td>5 not in [1,2,3] \u2192 True<\/td><\/tr>\n            <tr><td>is<\/td><td>Checks if two variables point to the same object<\/td><td>a is b<\/td><\/tr>\n            <tr><td>is not<\/td><td>Checks they do not point to the same object<\/td><td>a is not b<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Operator Precedence<\/h3>\n        <p>When multiple operators appear in one expression, Python follows a fixed order: <strong>Parentheses \u2192 Exponent \u2192 Multiplication\/Division \u2192 Addition\/Subtraction \u2192 Comparison \u2192 Logical<\/strong>.<\/p>\n        <div class=\"code-block\"><pre>result = 5 + 3 * 2      # Multiplication happens first\nprint(result)             # 11\n\nresult = (5 + 3) * 2     # Parentheses happen first\nprint(result)             # 16<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Write a program that takes two numbers as input and prints the result of all arithmetic operators (+, -, *, \/, \/\/, %, **) applied to them.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 4 -->\n    <div class=\"unit\" id=\"unit-4\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 4<\/span>\n        <h2>Input, Output &amp; String Formatting<\/h2>\n        <p>Talking to the user \u2014 print(), input() and f-strings.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>The print() Function<\/h3>\n        <p><code>print()<\/code> displays output on the screen. It accepts multiple values separated by commas and supports useful parameters like <code>sep<\/code> and <code>end<\/code>.<\/p>\n        <div class=\"code-block\"><pre>print(\"Hello\", \"World\")                 # Hello World\nprint(\"Hello\", \"World\", sep=\"-\")        # Hello-World\nprint(\"Hello\", end=\" \")\nprint(\"World\")                          # Hello World (same line)<\/pre><\/div>\n\n        <h3>The input() Function<\/h3>\n        <p><code>input()<\/code> reads text typed by the user from the keyboard. It <strong>always returns a string<\/strong> \u2014 even if the user types a number \u2014 so numeric input must be converted using <code>int()<\/code> or <code>float()<\/code>.<\/p>\n        <div class=\"code-block\"><pre>name = input(\"Enter your name: \")\nage = int(input(\"Enter your age: \"))\nprint(name, \"is\", age, \"years old\")<\/pre><\/div>\n\n        <h3>String Formatting Methods<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Method<\/th><th>Example<\/th><th>Output<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>f-string<\/td><td>f\"My name is {name}\"<\/td><td>My name is Ali<\/td><\/tr>\n            <tr><td>.format()<\/td><td>\"My name is {}\".format(name)<\/td><td>My name is Ali<\/td><\/tr>\n            <tr><td>% operator<\/td><td>\"My name is %s\" % name<\/td><td>My name is Ali<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>name = \"Ayesha\"\ngpa = 3.85\nprint(f\"Student: {name}, GPA: {gpa:.1f}\")\n# Output: Student: Ayesha, GPA: 3.9<\/pre><\/div>\n        <div class=\"info-box\">\ud83d\udca1 f-strings (Python 3.6+) are the modern, recommended way to format strings \u2014 faster and easier to read than <code>.format()<\/code> or <code>%<\/code> formatting.<\/div>\n\n        <h3>Escape Sequences<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Escape Sequence<\/th><th>Meaning<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>\\n<\/td><td>New line<\/td><\/tr>\n            <tr><td>\\t<\/td><td>Tab space<\/td><\/tr>\n            <tr><td>\\\\<\/td><td>Backslash<\/td><\/tr>\n            <tr><td>\\'<\/td><td>Single quote<\/td><\/tr>\n            <tr><td>\\\"<\/td><td>Double quote<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Write a program that asks the user for their name and CGPA, then prints a formatted sentence: \"Welcome, &lt;name&gt;! Your CGPA is &lt;value&gt;.\" using an f-string.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 5 -->\n    <div class=\"unit\" id=\"unit-5\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 5<\/span>\n        <h2>Decision Making \u2014 if, elif, else<\/h2>\n        <p>Making your program take decisions.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>The if Statement<\/h3>\n        <p>The <code>if<\/code> statement runs a block of code only when a condition is <strong>True<\/strong>. Python uses <strong>indentation<\/strong> instead of curly braces to define code blocks.<\/p>\n        <div class=\"code-block\"><pre>marks = 85\nif marks &gt;= 50:\n    print(\"You passed!\")<\/pre><\/div>\n\n        <h3>if-else Statement<\/h3>\n        <div class=\"code-block\"><pre>marks = 35\nif marks &gt;= 50:\n    print(\"You passed!\")\nelse:\n    print(\"You failed.\")<\/pre><\/div>\n\n        <h3>if-elif-else Ladder<\/h3>\n        <div class=\"code-block\"><pre>marks = 72\nif marks &gt;= 90:\n    grade = \"A\"\nelif marks &gt;= 80:\n    grade = \"B\"\nelif marks &gt;= 70:\n    grade = \"C\"\nelse:\n    grade = \"F\"\nprint(\"Grade:\", grade)<\/pre><\/div>\n\n        <h3>Nested if Statements<\/h3>\n        <p>An <code>if<\/code> placed inside another <code>if<\/code> is called a <strong>nested if<\/strong> \u2014 used when a decision depends on more than one condition.<\/p>\n        <div class=\"code-block\"><pre>age = 20\nhas_id = True\nif age &gt;= 18:\n    if has_id:\n        print(\"Entry allowed\")\n    else:\n        print(\"ID required\")\nelse:\n    print(\"Too young to enter\")<\/pre><\/div>\n\n        <h3>Ternary (Conditional) Operator<\/h3>\n        <p>A shorter, one-line way to write a simple if-else statement.<\/p>\n        <div class=\"code-block\"><pre>age = 17\nstatus = \"Adult\" if age &gt;= 18 else \"Minor\"\nprint(status)     # Minor<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Write a program that takes a student's marks as input and prints their grade (A, B, C, D, F) using an if-elif-else ladder.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 6 -->\n    <div class=\"unit\" id=\"unit-6\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 6<\/span>\n        <h2>Loops \u2014 for &amp; while<\/h2>\n        <p>Repeating tasks without writing the same code again and again.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>The for Loop<\/h3>\n        <p>A <code>for<\/code> loop iterates over a sequence (list, string, range, etc.) and repeats a block of code for each item.<\/p>\n        <div class=\"code-block\"><pre>for i in range(1, 6):\n    print(i)\n# Output: 1 2 3 4 5 (each on a new line)<\/pre><\/div>\n\n        <h3>The range() Function<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Syntax<\/th><th>Meaning<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>range(stop)<\/td><td>0 to stop-1<\/td><td>range(5) \u2192 0,1,2,3,4<\/td><\/tr>\n            <tr><td>range(start, stop)<\/td><td>start to stop-1<\/td><td>range(2,6) \u2192 2,3,4,5<\/td><\/tr>\n            <tr><td>range(start, stop, step)<\/td><td>with custom step<\/td><td>range(0,10,2) \u2192 0,2,4,6,8<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>The while Loop<\/h3>\n        <p>A <code>while<\/code> loop repeats a block of code <strong>as long as<\/strong> a condition stays True \u2014 used when you don't know in advance how many times to repeat.<\/p>\n        <div class=\"code-block\"><pre>count = 1\nwhile count &lt;= 5:\n    print(count)\n    count += 1<\/pre><\/div>\n\n        <h3>break, continue &amp; pass<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Keyword<\/th><th>Purpose<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>break<\/td><td>Immediately exits the loop<\/td><\/tr>\n            <tr><td>continue<\/td><td>Skips current iteration, moves to next<\/td><\/tr>\n            <tr><td>pass<\/td><td>Does nothing \u2014 a placeholder statement<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>for i in range(1, 10):\n    if i == 5:\n        break          # stop loop completely\n    if i % 2 == 0:\n        continue        # skip even numbers\n    print(i)\n# Output: 1 3<\/pre><\/div>\n\n        <h3>Nested Loops \u2014 Patterns<\/h3>\n        <div class=\"code-block\"><pre># Print a triangle pattern\nfor i in range(1, 5):\n    for j in range(i):\n        print(\"*\", end=\"\")\n    print()\n# Output:\n# *\n# **\n# ***\n# ****<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Write a program using a for loop to print the multiplication table (1 to 10) of any number entered by the user.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 7 -->\n    <div class=\"unit\" id=\"unit-7\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 7<\/span>\n        <h2>Strings &amp; String Methods<\/h2>\n        <p>Working with text data in Python.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is a String?<\/h3>\n        <p>A <strong>string<\/strong> is a sequence of characters enclosed in single (' '), double (\" \"), or triple (''' ''') quotes. Strings in Python are <strong>immutable<\/strong> \u2014 once created, individual characters cannot be changed directly.<\/p>\n        <div class=\"code-block\"><pre>s1 = 'Hello'\ns2 = \"World\"\ns3 = '''This is a\nmulti-line string'''<\/pre><\/div>\n\n        <h3>Indexing &amp; Slicing<\/h3>\n        <p>Each character has a position (index) starting from <strong>0<\/strong>. Negative indexes count from the end.<\/p>\n        <div class=\"code-block\"><pre>word = \"Python\"\nprint(word[0])      # P (first character)\nprint(word[-1])     # n (last character)\nprint(word[0:4])    # Pyth (index 0 to 3)\nprint(word[2:])     # thon (index 2 to end)\nprint(word[::-1])   # nohtyP (reversed string)<\/pre><\/div>\n\n        <h3>Common String Methods<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Method<\/th><th>Description<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>upper()<\/td><td>Converts to uppercase<\/td><td>\"hi\".upper() \u2192 \"HI\"<\/td><\/tr>\n            <tr><td>lower()<\/td><td>Converts to lowercase<\/td><td>\"HI\".lower() \u2192 \"hi\"<\/td><\/tr>\n            <tr><td>strip()<\/td><td>Removes leading\/trailing spaces<\/td><td>\" hi \".strip() \u2192 \"hi\"<\/td><\/tr>\n            <tr><td>replace()<\/td><td>Replaces text<\/td><td>\"hi\".replace(\"h\",\"H\") \u2192 \"Hi\"<\/td><\/tr>\n            <tr><td>split()<\/td><td>Splits into a list<\/td><td>\"a,b\".split(\",\") \u2192 ['a','b']<\/td><\/tr>\n            <tr><td>join()<\/td><td>Joins a list into a string<\/td><td>\"-\".join(['a','b']) \u2192 \"a-b\"<\/td><\/tr>\n            <tr><td>find()<\/td><td>Returns index of substring<\/td><td>\"hello\".find(\"l\") \u2192 2<\/td><\/tr>\n            <tr><td>len()<\/td><td>Returns length<\/td><td>len(\"hello\") \u2192 5<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>String Concatenation &amp; Repetition<\/h3>\n        <div class=\"code-block\"><pre>first = \"Pak\"\nlast = \"Notes\"\nprint(first + last)      # PakNotes  (concatenation)\nprint(first * 3)          # PakPakPak (repetition)<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Take a sentence as input and print: the total number of characters, the sentence in uppercase, and the sentence reversed.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 8 -->\n    <div class=\"unit\" id=\"unit-8\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 8<\/span>\n        <h2>Lists &amp; Tuples<\/h2>\n        <p>Storing collections of ordered data.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is a List?<\/h3>\n        <p>A <strong>list<\/strong> is an ordered, mutable collection that can hold items of different data types, defined using square brackets <code>[ ]<\/code>.<\/p>\n        <div class=\"code-block\"><pre>fruits = [\"apple\", \"banana\", \"cherry\"]\nmixed = [1, \"two\", 3.0, True]\nprint(fruits[0])        # apple\nfruits.append(\"mango\")  # add an item\nfruits[1] = \"grapes\"    # update an item\nprint(fruits)<\/pre><\/div>\n\n        <h3>Common List Methods<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>append(x)<\/td><td>Adds item x at the end<\/td><\/tr>\n            <tr><td>insert(i, x)<\/td><td>Inserts x at index i<\/td><\/tr>\n            <tr><td>remove(x)<\/td><td>Removes first occurrence of x<\/td><\/tr>\n            <tr><td>pop(i)<\/td><td>Removes &amp; returns item at index i<\/td><\/tr>\n            <tr><td>sort()<\/td><td>Sorts the list in ascending order<\/td><\/tr>\n            <tr><td>reverse()<\/td><td>Reverses the list<\/td><\/tr>\n            <tr><td>len(list)<\/td><td>Returns number of items<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>List Slicing<\/h3>\n        <div class=\"code-block\"><pre>numbers = [10, 20, 30, 40, 50]\nprint(numbers[1:4])     # [20, 30, 40]\nprint(numbers[:3])      # [10, 20, 30]\nprint(numbers[::2])     # [10, 30, 50] (every 2nd item)<\/pre><\/div>\n\n        <h3>List Comprehension (Introduction)<\/h3>\n        <p>A compact, one-line way to create a new list by transforming or filtering an existing one.<\/p>\n        <div class=\"code-block\"><pre>squares = [x**2 for x in range(1, 6)]\nprint(squares)             # [1, 4, 9, 16, 25]\n\nevens = [x for x in range(1, 11) if x % 2 == 0]\nprint(evens)                # [2, 4, 6, 8, 10]<\/pre><\/div>\n\n        <h3>What is a Tuple?<\/h3>\n        <p>A <strong>tuple<\/strong> is like a list but <strong>immutable<\/strong> \u2014 once created, its values cannot change. Tuples use parentheses <code>( )<\/code>.<\/p>\n        <div class=\"code-block\"><pre>point = (10, 20)\nprint(point[0])      # 10\n# point[0] = 5       # Error! Tuples cannot be modified<\/pre><\/div>\n\n        <h3>List vs Tuple<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Feature<\/th><th>List<\/th><th>Tuple<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Syntax<\/td><td>[1, 2, 3]<\/td><td>(1, 2, 3)<\/td><\/tr>\n            <tr><td>Mutable<\/td><td>Yes<\/td><td>No<\/td><\/tr>\n            <tr><td>Speed<\/td><td>Slower<\/td><td>Faster<\/td><\/tr>\n            <tr><td>Use Case<\/td><td>Data that changes<\/td><td>Fixed data (e.g. coordinates)<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Packing &amp; Unpacking<\/h3>\n        <div class=\"code-block\"><pre>point = (10, 20)\nx, y = point          # unpacking\nprint(x, y)             # 10 20\n\na, b, c = 1, 2, 3      # packing into separate variables<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Create a list of 5 students' marks. Find and print the highest, lowest, and average using <code>max()<\/code>, <code>min()<\/code>, and <code>sum()<\/code>.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 9 -->\n    <div class=\"unit\" id=\"unit-9\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 9<\/span>\n        <h2>Dictionaries &amp; Sets<\/h2>\n        <p>Key-value pairs and collections of unique items.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is a Dictionary?<\/h3>\n        <p>A <strong>dictionary<\/strong> stores data as <strong>key-value pairs<\/strong>. Each key must be unique, and values can be of any data type. Dictionaries use curly braces <code>{ }<\/code>.<\/p>\n        <div class=\"code-block\"><pre>student = {\"name\": \"Ali\", \"age\": 20, \"gpa\": 3.7}\nprint(student[\"name\"])       # Ali\nstudent[\"age\"] = 21            # update value\nstudent[\"dept\"] = \"CS\"         # add new key<\/pre><\/div>\n\n        <h3>Common Dictionary Methods<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>keys()<\/td><td>Returns all keys<\/td><\/tr>\n            <tr><td>values()<\/td><td>Returns all values<\/td><\/tr>\n            <tr><td>items()<\/td><td>Returns key-value pairs<\/td><\/tr>\n            <tr><td>get(key)<\/td><td>Safely returns value (no error if missing)<\/td><\/tr>\n            <tr><td>pop(key)<\/td><td>Removes a key and returns its value<\/td><\/tr>\n            <tr><td>update()<\/td><td>Adds\/updates multiple key-value pairs<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Iterating Over a Dictionary<\/h3>\n        <div class=\"code-block\"><pre>student = {\"name\": \"Ali\", \"age\": 20, \"gpa\": 3.7}\nfor key, value in student.items():\n    print(key, \"-&gt;\", value)<\/pre><\/div>\n\n        <h3>What is a Set?<\/h3>\n        <p>A <strong>set<\/strong> is an unordered collection of <strong>unique<\/strong> items \u2014 duplicates are automatically removed. Sets use curly braces <code>{ }<\/code> without key-value pairs.<\/p>\n        <div class=\"code-block\"><pre>nums = {1, 2, 2, 3, 3, 3}\nprint(nums)             # {1, 2, 3} \u2014 duplicates removed\nnums.add(4)\nnums.remove(1)<\/pre><\/div>\n\n        <h3>Set Operations<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Operation<\/th><th>Symbol<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Union<\/td><td>|<\/td><td>a | b<\/td><\/tr>\n            <tr><td>Intersection<\/td><td>&amp;<\/td><td>a &amp; b<\/td><\/tr>\n            <tr><td>Difference<\/td><td>-<\/td><td>a - b<\/td><\/tr>\n            <tr><td>Symmetric Difference<\/td><td>^<\/td><td>a ^ b<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>a = {1, 2, 3}\nb = {2, 3, 4}\nprint(a | b)    # {1, 2, 3, 4}  union\nprint(a &amp; b)    # {2, 3}        intersection\nprint(a - b)    # {1}           difference<\/pre><\/div>\n        <div class=\"info-box\">\ud83d\udca1 Dictionaries are perfect for storing structured records (like a student profile), while sets are perfect for removing duplicates and fast membership checks.<\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Create a dictionary to store a student's record (name, roll number, three subject marks). Calculate and print the total and percentage.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 10 -->\n    <div class=\"unit\" id=\"unit-10\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 10<\/span>\n        <h2>Functions &amp; Scope<\/h2>\n        <p>Writing reusable, organized blocks of code.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is a Function?<\/h3>\n        <p>A <strong>function<\/strong> is a reusable block of code that performs a specific task. Functions are defined using the <code>def<\/code> keyword and help avoid repeating code.<\/p>\n        <div class=\"code-block\"><pre>def greet(name):\n    print(f\"Hello, {name}!\")\n\ngreet(\"Sara\")         # Hello, Sara!\ngreet(\"Ahmed\")         # Hello, Ahmed!<\/pre><\/div>\n\n        <h3>Parameters &amp; Arguments<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Type<\/th><th>Description<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Positional<\/td><td>Passed in order<\/td><td>greet(\"Ali\")<\/td><\/tr>\n            <tr><td>Default<\/td><td>Has a fallback value<\/td><td>def greet(name=\"Guest\")<\/td><\/tr>\n            <tr><td>Keyword<\/td><td>Passed by parameter name<\/td><td>greet(name=\"Ali\")<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>def add(a, b=10):              # b has a default value\n    return a + b\n\nprint(add(5))            # 15 (uses default b=10)\nprint(add(5, 20))        # 25\nprint(add(a=5, b=2))     # 7 (keyword arguments)<\/pre><\/div>\n\n        <h3>*args and **kwargs<\/h3>\n        <p>Used when the number of arguments isn't fixed. <code>*args<\/code> collects extra positional arguments into a tuple, <code>**kwargs<\/code> collects extra keyword arguments into a dictionary.<\/p>\n        <div class=\"code-block\"><pre>def total(*args):\n    return sum(args)\nprint(total(1, 2, 3, 4))     # 10\n\ndef show_info(**kwargs):\n    for key, value in kwargs.items():\n        print(key, \":\", value)\nshow_info(name=\"Ali\", age=20)<\/pre><\/div>\n\n        <h3>The return Statement<\/h3>\n        <p><code>return<\/code> sends a value back to wherever the function was called, and immediately ends the function.<\/p>\n        <div class=\"code-block\"><pre>def square(n):\n    return n * n\n\nresult = square(5)\nprint(result)     # 25<\/pre><\/div>\n\n        <h3>Local vs Global Scope<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Scope<\/th><th>Description<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Local<\/td><td>Variable created inside a function \u2014 only accessible there<\/td><\/tr>\n            <tr><td>Global<\/td><td>Variable created outside any function \u2014 accessible everywhere<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>x = 10            # global variable\ndef show():\n    x = 5           # local variable (different from global x)\n    print(\"Inside:\", x)\nshow()               # Inside: 5\nprint(\"Outside:\", x) # Outside: 10<\/pre><\/div>\n\n        <h3>Recursion<\/h3>\n        <p>A <strong>recursive function<\/strong> calls itself to solve a smaller version of the same problem.<\/p>\n        <div class=\"code-block\"><pre>def factorial(n):\n    if n == 0:\n        return 1\n    return n * factorial(n - 1)\n\nprint(factorial(5))    # 120<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Write a function <code>is_prime(n)<\/code> that returns True if a number is prime, otherwise False. Test it for numbers 1 to 20.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 11 -->\n    <div class=\"unit\" id=\"unit-11\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 11<\/span>\n        <h2>Lambda, Map, Filter &amp; Comprehensions<\/h2>\n        <p>Writing short, powerful, functional-style code.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>Lambda Functions<\/h3>\n        <p>A <strong>lambda function<\/strong> is a small, anonymous (unnamed) function written in a single line \u2014 useful for short operations.<\/p>\n        <div class=\"code-block\"><pre>square = lambda x: x * x\nprint(square(5))         # 25\n\nadd = lambda a, b: a + b\nprint(add(3, 4))          # 7<\/pre><\/div>\n\n        <h3>The map() Function<\/h3>\n        <p><code>map()<\/code> applies a function to every item in a sequence and returns a new sequence of results.<\/p>\n        <div class=\"code-block\"><pre>numbers = [1, 2, 3, 4]\nsquares = list(map(lambda x: x**2, numbers))\nprint(squares)           # [1, 4, 9, 16]<\/pre><\/div>\n\n        <h3>The filter() Function<\/h3>\n        <p><code>filter()<\/code> keeps only the items for which a function returns True.<\/p>\n        <div class=\"code-block\"><pre>numbers = [1, 2, 3, 4, 5, 6]\nevens = list(filter(lambda x: x % 2 == 0, numbers))\nprint(evens)             # [2, 4, 6]<\/pre><\/div>\n\n        <h3>The reduce() Function<\/h3>\n        <p><code>reduce()<\/code> (from the <code>functools<\/code> module) repeatedly applies a function to reduce a sequence to a single value.<\/p>\n        <div class=\"code-block\"><pre>from functools import reduce\nnumbers = [1, 2, 3, 4]\nproduct = reduce(lambda a, b: a * b, numbers)\nprint(product)            # 24<\/pre><\/div>\n\n        <h3>Comprehensions \u2014 List, Dict &amp; Set<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Type<\/th><th>Syntax<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>List<\/td><td>[expr for x in seq]<\/td><td>[x*2 for x in range(5)]<\/td><\/tr>\n            <tr><td>Dict<\/td><td>{k:v for x in seq}<\/td><td>{x: x*2 for x in range(3)}<\/td><\/tr>\n            <tr><td>Set<\/td><td>{expr for x in seq}<\/td><td>{x%3 for x in range(10)}<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>squares_dict = {x: x**2 for x in range(1, 5)}\nprint(squares_dict)    # {1: 1, 2: 4, 3: 9, 4: 16}<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Use <code>map()<\/code> and a lambda function to convert a list of temperatures from Celsius to Fahrenheit (F = C * 9\/5 + 32).<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 12 -->\n    <div class=\"unit\" id=\"unit-12\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 12<\/span>\n        <h2>Exception Handling<\/h2>\n        <p>Catching and managing errors gracefully.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is an Exception?<\/h3>\n        <p>An <strong>exception<\/strong> is an error that occurs during program execution and stops the program unless it is handled. Python uses <code>try-except<\/code> blocks to catch and manage these errors gracefully.<\/p>\n        <div class=\"code-block\"><pre>print(10 \/ 0)\n# Output: ZeroDivisionError: division by zero<\/pre><\/div>\n\n        <h3>try-except Block<\/h3>\n        <div class=\"code-block\"><pre>try:\n    num = int(input(\"Enter a number: \"))\n    result = 10 \/ num\n    print(result)\nexcept ZeroDivisionError:\n    print(\"You cannot divide by zero!\")\nexcept ValueError:\n    print(\"Please enter a valid number!\")<\/pre><\/div>\n\n        <h3>Common Built-in Exceptions<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Exception<\/th><th>Occurs When<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>ZeroDivisionError<\/td><td>Dividing a number by zero<\/td><\/tr>\n            <tr><td>ValueError<\/td><td>Invalid value for an operation, e.g. int(\"abc\")<\/td><\/tr>\n            <tr><td>TypeError<\/td><td>Operation on incompatible types<\/td><\/tr>\n            <tr><td>IndexError<\/td><td>List index out of range<\/td><\/tr>\n            <tr><td>KeyError<\/td><td>Dictionary key not found<\/td><\/tr>\n            <tr><td>FileNotFoundError<\/td><td>File does not exist<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>else and finally<\/h3>\n        <p><code>else<\/code> runs only if no exception occurred, and <code>finally<\/code> always runs \u2014 whether an exception occurred or not (useful for cleanup).<\/p>\n        <div class=\"code-block\"><pre>try:\n    x = int(\"10\")\nexcept ValueError:\n    print(\"Invalid input\")\nelse:\n    print(\"No errors:\", x)\nfinally:\n    print(\"Execution finished\")<\/pre><\/div>\n\n        <h3>Raising Exceptions \u2014 raise<\/h3>\n        <div class=\"code-block\"><pre>def set_age(age):\n    if age &lt; 0:\n        raise ValueError(\"Age cannot be negative\")\n    return age\n\nset_age(-5)    # raises ValueError<\/pre><\/div>\n\n        <h3>Custom Exceptions<\/h3>\n        <div class=\"code-block\"><pre>class InsufficientBalanceError(Exception):\n    pass\n\ndef withdraw(balance, amount):\n    if amount &gt; balance:\n        raise InsufficientBalanceError(\"Not enough balance!\")\n    return balance - amount<\/pre><\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Write a program that asks the user for two numbers and divides them. Handle ZeroDivisionError and ValueError using try-except, and print \"Done\" in the finally block.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 13 -->\n    <div class=\"unit\" id=\"unit-13\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 13<\/span>\n        <h2>File Handling<\/h2>\n        <p>Reading from and writing to files on disk.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>Opening a File \u2014 open()<\/h3>\n        <p>Python's <code>open()<\/code> function is used to work with files. It takes a filename and a <strong>mode<\/strong> that specifies the operation to perform.<\/p>\n        <div class=\"code-block\"><pre>file = open(\"notes.txt\", \"r\")     # open for reading\ncontent = file.read()\nfile.close()                        # always close the file<\/pre><\/div>\n\n        <h3>File Modes<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Mode<\/th><th>Meaning<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>\"r\"<\/td><td>Read (default) \u2014 file must exist<\/td><\/tr>\n            <tr><td>\"w\"<\/td><td>Write \u2014 creates new file or overwrites existing<\/td><\/tr>\n            <tr><td>\"a\"<\/td><td>Append \u2014 adds data at the end of the file<\/td><\/tr>\n            <tr><td>\"r+\"<\/td><td>Read and write<\/td><\/tr>\n            <tr><td>\"x\"<\/td><td>Create a new file \u2014 fails if it already exists<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Reading from a File<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>read()<\/td><td>Reads the entire file as one string<\/td><\/tr>\n            <tr><td>readline()<\/td><td>Reads a single line<\/td><\/tr>\n            <tr><td>readlines()<\/td><td>Reads all lines into a list<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"code-block\"><pre>with open(\"notes.txt\", \"r\") as file:\n    for line in file:\n        print(line.strip())<\/pre><\/div>\n\n        <h3>Writing to a File<\/h3>\n        <div class=\"code-block\"><pre>with open(\"notes.txt\", \"w\") as file:\n    file.write(\"Pak Notes Hub\\n\")\n    file.write(\"Python Programming Course\\n\")\n\nwith open(\"notes.txt\", \"a\") as file:\n    file.write(\"Added later using append mode\\n\")<\/pre><\/div>\n\n        <h3>The with Statement<\/h3>\n        <p>Using <code>with open(...) as file:<\/code> automatically closes the file when the block ends \u2014 even if an error occurs. This is the <strong>recommended<\/strong> way to work with files.<\/p>\n        <div class=\"info-box\">\ud83d\udca1 Without <code>with<\/code>, you must manually call <code>file.close()<\/code> \u2014 forgetting it can cause data loss or memory issues. Always prefer the <code>with<\/code> statement.<\/div>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Write a program that asks for 5 student names and writes them to a file <code>students.txt<\/code>, one name per line. Then read and display the file's contents.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 14 -->\n    <div class=\"unit\" id=\"unit-14\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 14<\/span>\n        <h2>Object-Oriented Programming (OOP)<\/h2>\n        <p>Classes, objects, and the four pillars of OOP.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is OOP? \u2014 The Four Pillars<\/h3>\n        <div class=\"concept-grid\">\n          <div class=\"concept-card\"><div class=\"concept-name\">Encapsulation<\/div><div class=\"concept-rule\">Bundling data &amp; methods together<\/div><\/div>\n          <div class=\"concept-card\"><div class=\"concept-name\">Inheritance<\/div><div class=\"concept-rule\">Reusing code from a parent class<\/div><\/div>\n          <div class=\"concept-card\"><div class=\"concept-name\">Polymorphism<\/div><div class=\"concept-rule\">Same method, different behavior<\/div><\/div>\n          <div class=\"concept-card\"><div class=\"concept-name\">Abstraction<\/div><div class=\"concept-rule\">Hiding complex implementation details<\/div><\/div>\n        <\/div>\n\n        <h3>Classes &amp; Objects<\/h3>\n        <p>A <strong>class<\/strong> is a blueprint for creating objects. An <strong>object<\/strong> is an instance of a class with its own data.<\/p>\n        <div class=\"code-block\"><pre>class Student:\n    def __init__(self, name, roll_no):\n        self.name = name\n        self.roll_no = roll_no\n\n    def display(self):\n        print(f\"{self.roll_no} - {self.name}\")\n\ns1 = Student(\"Ali\", 101)\ns1.display()           # 101 - Ali<\/pre><\/div>\n\n        <h3>__init__ Constructor &amp; self<\/h3>\n        <p><code>__init__<\/code> is a special method automatically called when an object is created \u2014 it initializes the object's attributes. <code>self<\/code> refers to the current object instance.<\/p>\n\n        <h3>Instance vs Class Variables<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Type<\/th><th>Description<\/th><th>Example<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Instance Variable<\/td><td>Belongs to one specific object<\/td><td>self.name<\/td><\/tr>\n            <tr><td>Class Variable<\/td><td>Shared by all objects of the class<\/td><td>Student.school_name<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Inheritance<\/h3>\n        <p>Inheritance allows a <strong>child class<\/strong> to reuse the attributes and methods of a <strong>parent class<\/strong>.<\/p>\n        <div class=\"code-block\"><pre>class Person:\n    def __init__(self, name):\n        self.name = name\n    def show(self):\n        print(\"Name:\", self.name)\n\nclass Student(Person):            # Student inherits from Person\n    def __init__(self, name, roll_no):\n        super().__init__(name)     # call parent constructor\n        self.roll_no = roll_no\n\ns = Student(\"Sara\", 12)\ns.show()                # Name: Sara<\/pre><\/div>\n\n        <h3>Polymorphism<\/h3>\n        <p>Polymorphism means the same method name behaves differently for different classes.<\/p>\n        <div class=\"code-block\"><pre>class Cat:\n    def sound(self):\n        print(\"Meow\")\n\nclass Dog:\n    def sound(self):\n        print(\"Woof\")\n\nfor animal in [Cat(), Dog()]:\n    animal.sound()        # Meow, then Woof<\/pre><\/div>\n\n        <h3>Encapsulation<\/h3>\n        <p>Encapsulation restricts direct access to an object's data using <strong>private<\/strong> (double underscore <code>__<\/code>) or <strong>protected<\/strong> (single underscore <code>_<\/code>) attributes.<\/p>\n        <div class=\"code-block\"><pre>class Account:\n    def __init__(self, balance):\n        self.__balance = balance      # private attribute\n\n    def deposit(self, amount):\n        self.__balance += amount\n\n    def get_balance(self):\n        return self.__balance<\/pre><\/div>\n\n        <h3>Dunder (Magic) Methods<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Method<\/th><th>Purpose<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>__init__<\/td><td>Object constructor<\/td><\/tr>\n            <tr><td>__str__<\/td><td>Defines what print(object) displays<\/td><\/tr>\n            <tr><td>__len__<\/td><td>Defines behavior of len(object)<\/td><\/tr>\n            <tr><td>__add__<\/td><td>Defines behavior of the + operator<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Create a class <code>Book<\/code> with attributes title, author, and price. Add a method <code>discount()<\/code> that reduces the price by 10%. Create two Book objects and display their details.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 UNIT 15 -->\n    <div class=\"unit\" id=\"unit-15\">\n      <div class=\"unit-header\">\n        <span class=\"unit-num-badge\">Unit 15<\/span>\n        <h2>Modules, Packages &amp; Final Project<\/h2>\n        <p>Organizing code and building a real mini-project.<\/p>\n      <\/div>\n      <div class=\"unit-body\">\n        <h3>What is a Module?<\/h3>\n        <p>A <strong>module<\/strong> is simply a Python file (.py) containing functions, classes, or variables that can be reused in other programs using <code>import<\/code>.<\/p>\n        <div class=\"code-block\"><pre>import math\nprint(math.sqrt(25))      # 5.0\nprint(math.pi)              # 3.141592653589793\n\nfrom random import randint\nprint(randint(1, 10))      # random number between 1 and 10<\/pre><\/div>\n\n        <h3>Useful Standard Library Modules<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Module<\/th><th>Purpose<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>math<\/td><td>Mathematical functions (sqrt, pow, pi)<\/td><\/tr>\n            <tr><td>random<\/td><td>Generate random numbers<\/td><\/tr>\n            <tr><td>datetime<\/td><td>Work with dates and times<\/td><\/tr>\n            <tr><td>os<\/td><td>Interact with the operating system<\/td><\/tr>\n            <tr><td>sys<\/td><td>System-specific parameters &amp; functions<\/td><\/tr>\n            <tr><td>time<\/td><td>Time-related functions, delays<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n\n        <h3>Creating Your Own Module<\/h3>\n        <p>Save any Python file (e.g. <code>mymath.py<\/code>) and import it into another file in the same folder using <code>import mymath<\/code>.<\/p>\n        <div class=\"code-block\"><pre># mymath.py\ndef add(a, b):\n    return a + b\n\n# main.py\nimport mymath\nprint(mymath.add(3, 4))     # 7<\/pre><\/div>\n\n        <h3>Packages &amp; pip<\/h3>\n        <p>A <strong>package<\/strong> is a folder containing multiple related modules. Python's package manager, <code>pip<\/code>, installs third-party packages from PyPI (Python Package Index).<\/p>\n        <div class=\"code-block\"><pre>pip install numpy\npip install pandas\npip list                     # shows installed packages<\/pre><\/div>\n\n        <h3>Final Project \u2014 Console-Based To-Do List<\/h3>\n        <p>Let's combine everything learned \u2014 functions, loops, lists, dictionaries, and exception handling \u2014 into one mini project.<\/p>\n        <div class=\"code-block\"><pre>tasks = []\n\ndef show_menu():\n    print(\"\\n--- TO-DO LIST ---\")\n    print(\"1. Add Task\")\n    print(\"2. View Tasks\")\n    print(\"3. Remove Task\")\n    print(\"4. Exit\")\n\ndef add_task():\n    task = input(\"Enter task: \")\n    tasks.append(task)\n    print(\"Task added!\")\n\ndef view_tasks():\n    if not tasks:\n        print(\"No tasks yet.\")\n    for i, task in enumerate(tasks, start=1):\n        print(f\"{i}. {task}\")\n\ndef remove_task():\n    view_tasks()\n    try:\n        num = int(input(\"Enter task number to remove: \"))\n        tasks.pop(num - 1)\n        print(\"Task removed!\")\n    except (ValueError, IndexError):\n        print(\"Invalid task number.\")\n\nwhile True:\n    show_menu()\n    choice = input(\"Choose an option: \")\n    if choice == \"1\":\n        add_task()\n    elif choice == \"2\":\n        view_tasks()\n    elif choice == \"3\":\n        remove_task()\n    elif choice == \"4\":\n        print(\"Goodbye!\")\n        break\n    else:\n        print(\"Invalid choice, try again.\")<\/pre><\/div>\n\n        <h3>\ud83d\udc0d Python Quick Reference \u2014 Syntax Cheat Sheet<\/h3>\n        <table class=\"data-table\">\n          <thead><tr><th>Concept<\/th><th>Syntax<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td>Variable<\/td><td>x = 10<\/td><\/tr>\n            <tr><td>If statement<\/td><td>if x &gt; 5:<\/td><\/tr>\n            <tr><td>For loop<\/td><td>for i in range(5):<\/td><\/tr>\n            <tr><td>While loop<\/td><td>while x &gt; 0:<\/td><\/tr>\n            <tr><td>Function<\/td><td>def func(x):<\/td><\/tr>\n            <tr><td>Class<\/td><td>class Name:<\/td><\/tr>\n            <tr><td>List<\/td><td>[1, 2, 3]<\/td><\/tr>\n            <tr><td>Dictionary<\/td><td>{\"key\": \"value\"}<\/td><\/tr>\n            <tr><td>Import<\/td><td>import module<\/td><\/tr>\n            <tr><td>Try-Except<\/td><td>try: ... except Error:<\/td><\/tr>\n            <tr><td>File Read<\/td><td>with open(\"f.txt\") as f:<\/td><\/tr>\n            <tr><td>Lambda<\/td><td>lambda x: x*2<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Extend the To-Do List project by adding a feature to save tasks to a file (<code>tasks.txt<\/code>) and load them back when the program starts, using file handling.<\/div>\n      <\/div>\n    <\/div>\n\n    <!-- CONGRATS -->\n    <div class=\"congrats\">\n      <h2>\ud83c\udf89 Congratulations!<\/h2>\n      <p>You have completed the <strong>Python Programming<\/strong> Course by Pak Notes Hub!<\/p>\n      <p style=\"margin-top:.5rem; font-size:.9rem;\">You now know Variables, Data Types, Control Flow, Functions, Data Structures, OOP, File &amp; Exception Handling \u2014 and even built a real mini-project. Best of luck in your exams and coding journey! \ud83c\udf1f<\/p>\n    <\/div>\n\n    <!-- SUMMARY -->\n    <div class=\"unit\">\n      <div class=\"unit-header\"><h2>\ud83d\udcca Course Summary<\/h2><\/div>\n      <div class=\"unit-body\">\n        <table class=\"data-table\">\n          <thead><tr><th>#<\/th><th>Unit<\/th><th>Key Concept<\/th><\/tr><\/thead>\n          <tbody>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">1<\/td><td>Introduction to Python<\/td><td>History, Features, First Program<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">2<\/td><td>Variables &amp; Data Types<\/td><td>int, float, str, bool, type casting<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">3<\/td><td>Operators &amp; Expressions<\/td><td>Arithmetic, Logical, Comparison<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">4<\/td><td>Input, Output &amp; Formatting<\/td><td>print(), input(), f-strings<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">5<\/td><td>Decision Making<\/td><td>if, elif, else, ternary operator<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">6<\/td><td>Loops<\/td><td>for, while, break, continue<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">7<\/td><td>Strings<\/td><td>Indexing, slicing, string methods<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">8<\/td><td>Lists &amp; Tuples<\/td><td>Mutable vs immutable sequences<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">9<\/td><td>Dictionaries &amp; Sets<\/td><td>Key-value pairs, unique collections<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">10<\/td><td>Functions &amp; Scope<\/td><td>def, *args, **kwargs, recursion<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">11<\/td><td>Lambda &amp; Comprehensions<\/td><td>map, filter, reduce, comprehensions<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">12<\/td><td>Exception Handling<\/td><td>try, except, else, finally, raise<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">13<\/td><td>File Handling<\/td><td>open(), read\/write, with statement<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">14<\/td><td>OOP in Python<\/td><td>Classes, Inheritance, Polymorphism<\/td><\/tr>\n            <tr><td style=\"color:var(--green);font-weight:700;font-family:inherit\">15<\/td><td>Modules &amp; Final Project<\/td><td>import, pip, To-Do List project<\/td><\/tr>\n          <\/tbody>\n        <\/table>\n      <\/div>\n    <\/div>\n\n    <p style=\"text-align:center; color:var(--mid); font-size:.85rem; padding-bottom:1rem;\">\n      www.paknoteshub.online &nbsp;\u00b7&nbsp; More courses coming soon!\n    <\/p>\n  <\/main>\n<\/div>\n\n<button id=\"back-top\" onclick=\"window.scrollTo({top:0,behavior:'smooth'})\">\u2191<\/button>\n\n<script>\n  const progress = document.getElementById('progress');\n  window.addEventListener('scroll', () => {\n    const h = document.documentElement;\n    progress.style.width = (h.scrollTop \/ (h.scrollHeight - h.clientHeight) * 100) + '%';\n    document.getElementById('back-top').classList.toggle('visible', h.scrollTop > 400);\n  });\n  document.querySelectorAll('.unit, #toc-section').forEach(unit => {\n    new IntersectionObserver((entries) => {\n      entries.forEach(e => {\n        if (e.isIntersecting) {\n          document.querySelectorAll('.toc-list a').forEach(a => a.classList.remove('active'));\n          const a = document.querySelector(`.toc-list a[href=\"#${e.target.id}\"]`);\n          if (a) a.classList.add('active');\n        }\n      });\n    }, { rootMargin: '-20% 0px -70% 0px' }).observe(unit);\n  });\n<\/script>\n<\/body>\n<\/html>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Python Programming \u2013 University Level \u2013 Pak Notes Hub Pak Notes Hub Course Outline Start Learning Functions OOP &amp; Project \ud83d\udc0d University Level \u2014 BS CS \/ BS IT Python ProgrammingComplete Notes Variables to OOP \u00b7 Data Structures \u00b7 File &amp; Exception Handling \u2014 All in Easy English \ud83d\udc0d 15 Units \ud83c\udf93 University Level \ud83d\udcbb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_angie_page":false,"footnotes":""},"class_list":["post-437","page","type-page","status-publish","hentry"],"_hostinger_reach_plugin_has_subscription_block":false,"_hostinger_reach_plugin_is_elementor":false,"_links":{"self":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages\/437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=437"}],"version-history":[{"count":4,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages\/437\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages\/437\/revisions\/441"}],"wp:attachment":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}