{"id":495,"date":"2025-05-19T11:34:34","date_gmt":"2025-05-19T11:34:34","guid":{"rendered":"https:\/\/buhave.com\/courses\/?p=495"},"modified":"2025-05-20T12:57:18","modified_gmt":"2025-05-20T12:57:18","slug":"intermediate-topics","status":"publish","type":"post","link":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/","title":{"rendered":"Intermediate Topics"},"content":{"rendered":"<h2>List comprehensions (advanced)<span style=\"font-weight: 400\"><br \/>\n<\/span><\/h2>\n<p>List comprehensions are a powerful and expressive way to create lists in Python using a single line of code. While basic list comprehensions handle simple transformations, advanced list comprehensions allow for more complex logic, including conditional filtering, nested loops, and function application.<\/p>\n<p><strong>Basic Structure (Recap)<\/strong><\/p>\n<p style=\"text-align: center\"><em>[expression for item in iterable if condition]<\/em><\/p>\n<h3>1. Conditional Logic (if&#8230;else inside)<\/h3>\n<p><strong>You can use an inline if&#8230;else in the expression part to choose different values:<\/strong><\/p>\n<p style=\"text-align: center\"># Label even\/odd numbers<br \/>\nresult = [&#8216;even&#8217; if x % 2 == 0 else &#8216;odd&#8217; for x in range(5)]<br \/>\n# Output: [&#8216;even&#8217;, &#8216;odd&#8217;, &#8216;even&#8217;, &#8216;odd&#8217;, &#8216;even&#8217;]<\/p>\n<p><strong>Note:<\/strong> if&#8230;else must go before the for loop, unlike a simple if filter which comes after.<\/p>\n<h3>2. Nested Loops<\/h3>\n<p><strong>List comprehensions can handle multiple loops just like nested for loops.<\/strong><\/p>\n<p style=\"text-align: center\"><em># Cartesian product<\/em><br \/>\n<em>pairs = [(x, y) for x in [1, 2] for y in [&#8216;a&#8217;, &#8216;b&#8217;]]<\/em><br \/>\n<em># Output: [(1, &#8216;a&#8217;), (1, &#8216;b&#8217;), (2, &#8216;a&#8217;), (2, &#8216;b&#8217;)]<\/em><\/p>\n<p>Loop order follows the same nesting as regular for-loops.<\/p>\n<h3>3. Using Functions in List Comprehensions<\/h3>\n<p><strong>Apply functions directly inside the comprehension:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def square(x):<\/em><br \/>\n<em>return x * x<\/em><\/p>\n<p style=\"text-align: center\"><em>squares = [square(i) for i in range(5)]<\/em><br \/>\n<em># Output: [0, 1, 4, 9, 16]<\/em><\/p>\n<p><strong>You can also use built-in functions or lambdas:<\/strong><\/p>\n<p style=\"text-align: center\"><em>words = [&#8220;hello&#8221;, &#8220;world&#8221;, &#8220;python&#8221;]<\/em><br \/>\n<em>lengths = [len(word) for word in words]<\/em><br \/>\n<em># Output: [5, 5, 6]<\/em><\/p>\n<h3>4. Combining Multiple Conditions<\/h3>\n<p><strong>Add multiple if statements for filtering:<\/strong><\/p>\n<p style=\"text-align: center\"><em># Numbers divisible by both 2 and 3<\/em><br \/>\n<em>nums = [x for x in range(20) if x % 2 == 0 if x % 3 == 0]<\/em><br \/>\n<em># Output: [0, 6, 12, 18]<\/em><\/p>\n<h3>5. Flattening Nested Lists<\/h3>\n<p><strong>List comprehensions can flatten 2D lists:<\/strong><\/p>\n<p style=\"text-align: center\"><em>matrix = [[1, 2], [3, 4], [5, 6]]<\/em><br \/>\n<em>flattened = [num for row in matrix for num in row]<\/em><br \/>\n<em># Output: [1, 2, 3, 4, 5, 6]<\/em><\/p>\n<h3>6. With Enumerate or Zip<\/h3>\n<p><strong>You can also use enumerate() or zip() for more advanced use cases:<\/strong><\/p>\n<p><strong>Summary:<\/strong><\/p>\n<p><strong>Advanced list comprehensions allow:<\/strong><\/p>\n<ul>\n<li>Conditional value assignment (if&#8230;else)<\/li>\n<li>Nested loops<\/li>\n<li>Function application<\/li>\n<li>Filtering with multiple conditions<\/li>\n<li>Flattening nested lists<\/li>\n<li>Integration with built-ins like zip(), enumerate()<\/li>\n<\/ul>\n<h2>Generators and iterators<\/h2>\n<p>Generators and Iterators \u2013 Detailed Explanation<br \/>\nGenerators and iterators are powerful tools in Python for working with sequences of data without loading everything into memory. They are essential when dealing with large datasets, streams, or lazy evaluation.<\/p>\n<h3>What is an Iterator?<\/h3>\n<ul>\n<li>An iterator is an object that implements the iterator protocol:<\/li>\n<li>It has a __iter__() method (returns the iterator object itself).<\/li>\n<li>It has a __next__() method (returns the next value, or raises StopIteration when done).<\/li>\n<\/ul>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>nums = iter([1, 2, 3])<\/em><\/p>\n<p style=\"text-align: center\"><em>print(next(nums)) # 1<\/em><br \/>\n<em>print(next(nums)) # 2<\/em><br \/>\n<em>print(next(nums)) # 3<\/em><br \/>\n<em># next(nums) # Raises StopIteration<\/em><\/p>\n<p>You can create custom iterators by defining classes with __iter__() and __next__() methods.<\/p>\n<h3>What is a Generator?<\/h3>\n<p>A generator is a simpler way to create an iterator using functions and the yield keyword. Unlike return, yield pauses the function and saves its state for resumption.<\/p>\n<p><strong>Generator Function Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def count_up_to(n):<\/em><br \/>\n<em>i = 1<\/em><br \/>\n<em>while i &lt;= n:<\/em><br \/>\n<em>yield i<\/em><br \/>\n<em>i += 1<\/em><\/p>\n<p style=\"text-align: center\"><em>counter = count_up_to(3)<\/em><\/p>\n<p style=\"text-align: center\"><em>for num in counter:<\/em><br \/>\n<em>print(num)<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p style=\"text-align: center\"><em>1<\/em><br \/>\n<em>2<\/em><br \/>\n<em>3<\/em><\/p>\n<p>Each call to next(counter) continues from where it left off after yield.<\/p>\n<p><strong>Generator Expressions<\/strong><\/p>\n<p>Like list comprehensions but more memory-efficient because they generate items on the fly.<\/p>\n<p style=\"text-align: center\"><em>gen = (x * x for x in range(5))<\/em><br \/>\n<em>print(next(gen)) # 0<\/em><br \/>\n<em>print(next(gen)) # 1<\/em><\/p>\n<p><strong>Why Use Generators?<\/strong><\/p>\n<ul>\n<li>Memory-efficient: They don\u2019t store the entire sequence in memory.<\/li>\n<li>Lazy evaluation: They compute values only when needed.<\/li>\n<li>Composability: Easily chain multiple generators.<\/li>\n<\/ul>\n<p><strong>When to Use Iterators vs Generators<\/strong><\/p>\n<table style=\"border-collapse: collapse;width: 100%;font-family: Arial, sans-serif\" border=\"1\" cellspacing=\"0\" cellpadding=\"8\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd\"><strong>Feature<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd\"><strong>Iterator (Manual)<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #ddd\"><strong>Generator (Function\/yield)<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\"><strong>Syntax<\/strong><\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Requires class with <code>__iter__()<\/code> and <code>__next__()<\/code><\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Uses function with <code>yield<\/code> statements<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\"><strong>Implementation<\/strong><\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Explicit iteration protocol<\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Implicit iteration via generator protocol<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\"><strong>Use Case<\/strong><\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Complex iteration logic with custom state<\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Lazy evaluation and memory-efficient sequences<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\"><strong>Memory<\/strong><\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Typically stores complete collection<\/td>\n<td style=\"padding: 12px;border-bottom: 1px solid #ddd\">Generates items on-demand (memory efficient)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px\"><strong>Performance<\/strong><\/td>\n<td style=\"padding: 12px\">Slightly faster for small collections<\/td>\n<td style=\"padding: 12px\">Better for large\/infinite sequences<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Custom Iterator Example<\/strong><\/p>\n<p style=\"text-align: center\"><em>class Countdown:<\/em><br \/>\n<em>def __init__(self, start):<\/em><br \/>\n<em>self.current = start<\/em><\/p>\n<p style=\"text-align: center\"><em>def __iter__(self):<\/em><br \/>\n<em>return self<\/em><\/p>\n<p style=\"text-align: center\"><em>def __next__(self):<\/em><br \/>\n<em>if self.current &lt;= 0:<\/em><br \/>\n<em>raise StopIteration<\/em><br \/>\n<em>self.current -= 1<\/em><br \/>\n<em>return self.current + 1<\/em><\/p>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>Iterators follow a protocol (__iter__, __next__) and require more boilerplate.<\/li>\n<li>Generators simplify iteration with yield, ideal for streaming or large data.<\/li>\n<li>Generator expressions are concise and lazy alternatives to list comprehensions.<\/li>\n<\/ul>\n<h2>Decorators<\/h2>\n<p><strong>Python Decorators \u2013 Detailed Explanation<\/strong><\/p>\n<p>A decorator in Python is a powerful and elegant way to modify or extend the behavior of functions or methods without changing their actual code. Decorators use higher-order functions (functions that return or accept other functions) and are often used for logging, access control, timing, memoization, and more.<\/p>\n<h3>Basics of Functions as First-Class Objects<\/h3>\n<p><strong>In Python, functions can be:<\/strong><\/p>\n<ul>\n<li>Passed as arguments to other functions<\/li>\n<li>Returned from other functions<\/li>\n<li>Assigned to variables<\/li>\n<li>This is the foundation of decorators.<\/li>\n<\/ul>\n<p><strong>What is a Decorator?<\/strong><\/p>\n<p>A decorator is a function that takes another function as input, adds some functionality, and returns it.<\/p>\n<p><strong>Basic Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def my_decorator(func):<\/em><br \/>\n<em>def wrapper():<\/em><br \/>\n<em>print(&#8220;Before the function runs.&#8221;)<\/em><br \/>\n<em>func()<\/em><br \/>\n<em>print(&#8220;After the function runs.&#8221;)<\/em><br \/>\n<em>return wrapper<\/em><\/p>\n<p style=\"text-align: center\"><em>@my_decorator<\/em><br \/>\n<em>def greet():<\/em><br \/>\n<em>print(&#8220;Hello!&#8221;)<\/em><\/p>\n<p style=\"text-align: center\"><em>greet()<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p style=\"text-align: center\"><em>Before the function runs.<\/em><br \/>\n<em>Hello!<\/em><br \/>\n<em>After the function runs.<\/em><\/p>\n<p>The @my_decorator syntax is shorthand for:<\/p>\n<p style=\"text-align: center\"><em>greet = my_decorator(greet)<\/em><\/p>\n<p><strong>Writing a Decorator That Accepts Arguments<\/strong><\/p>\n<p style=\"text-align: center\"><em>def repeat(num_times):<\/em><br \/>\n<em>def decorator(func):<\/em><br \/>\n<em>def wrapper(*args, **kwargs):<\/em><br \/>\n<em>for _ in range(num_times):<\/em><br \/>\n<em>func(*args, **kwargs)<\/em><br \/>\n<em>return wrapper<\/em><br \/>\n<em>return decorator<\/em><\/p>\n<p style=\"text-align: center\"><em>@repeat(3)<\/em><br \/>\n<em>def say_hello():<\/em><br \/>\n<em>print(&#8220;Hello!&#8221;)<\/em><\/p>\n<p style=\"text-align: center\"><em>say_hello()<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p style=\"text-align: center\"><em>Hello!<\/em><br \/>\n<em>Hello!<\/em><br \/>\n<em>Hello!<\/em><\/p>\n<p><strong> Common Use Cases<\/strong><\/p>\n<p><strong>1. Logging:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def logger(func):<\/em><br \/>\n<em>def wrapper(*args, **kwargs):<\/em><br \/>\n<em>print(f&#8221;Calling {func.__name__} with {args}, {kwargs}&#8221;)<\/em><br \/>\n<em>return func(*args, **kwargs)<\/em><br \/>\n<em>return wrapper<\/em><\/p>\n<p><strong>2. Timing:<\/strong><\/p>\n<p style=\"text-align: center\"><em>import time<\/em><\/p>\n<p style=\"text-align: center\"><em>def timer(func):<\/em><br \/>\n<em>def wrapper(*args, **kwargs):<\/em><br \/>\n<em>start = time.time()<\/em><br \/>\n<em>result = func(*args, **kwargs)<\/em><br \/>\n<em>end = time.time()<\/em><br \/>\n<em>print(f&#8221;{func.__name__} took {end &#8211; start:.4f} seconds&#8221;)<\/em><br \/>\n<em>return result<\/em><br \/>\n<em>return wrapper<\/em><\/p>\n<p><strong>3. Authentication \/ Authorization (often in web apps).<\/strong><\/p>\n<p><strong>Using functools.wraps<\/strong><\/p>\n<p>Always use @functools.wraps(func) in your wrapper to preserve the original function\u2019s name, docstring, and metadata:<\/p>\n<p>from functools import wraps<\/p>\n<p style=\"text-align: center\"><em>def my_decorator(func):<\/em><br \/>\n<em>@wraps(func)<\/em><br \/>\n<em>def wrapper(*args, **kwargs):<\/em><br \/>\n<em>print(&#8220;Wrapped function&#8221;)<\/em><br \/>\n<em>return func(*args, **kwargs)<\/em><br \/>\n<em>return wrapper<\/em><\/p>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>A decorator is a callable that takes a function and returns a modified version of it.<\/li>\n<li>Use @decorator_name syntax to apply a decorator.<\/li>\n<li>They support use cases like logging, access control, caching, validation, and performance monitoring.<\/li>\n<li>Decorators can be stacked, parameterized, and used on methods or classes too.<\/li>\n<\/ul>\n<h2>Context managers<\/h2>\n<p><strong>Context Managers in Python \u2013 Detailed Explanation<\/strong><\/p>\n<p>A context manager in Python is a construct that properly manages resources (like files, network connections, or database sessions), ensuring they are acquired and released cleanly \u2014 even if errors occur.<\/p>\n<p>They are commonly used with the with statement for automatic setup and teardown of resources.<\/p>\n<h3>Why Use a Context Manager?<\/h3>\n<ul>\n<li>Ensures resources are freed correctly, even in case of exceptions.<\/li>\n<li>Helps avoid issues like file leaks, open sockets, or unclosed connections.<\/li>\n<li>Makes code cleaner and more readable.<\/li>\n<\/ul>\n<p><strong>Common Use Case:<\/strong> File Handling<\/p>\n<p style=\"text-align: center\"><em>with open(&#8216;data.txt&#8217;, &#8216;r&#8217;) as f:<\/em><br \/>\n<em>content = f.read()<\/em><br \/>\n<em># File is automatically closed here<\/em><\/p>\n<p>This is cleaner and safer than:<\/p>\n<p style=\"text-align: center\"><em>f = open(&#8216;data.txt&#8217;, &#8216;r&#8217;)<\/em><br \/>\n<em>try:<\/em><br \/>\n<em>content = f.read()<\/em><br \/>\n<em>finally:<\/em><br \/>\n<em>f.close()<\/em><\/p>\n<p><strong>How Does It Work?<\/strong><\/p>\n<ul>\n<li>Behind the scenes, a context manager is any object that implements:<\/li>\n<li>__enter__() \u2013 sets things up and returns the resource.<\/li>\n<li>__exit__(exc_type, exc_value, traceback) \u2013 cleans up the resource.<\/li>\n<\/ul>\n<p><strong>Creating a Custom Context Manager (Using a Class)<\/strong><\/p>\n<p style=\"text-align: center\"><em>class OpenFile:<\/em><br \/>\n<em>def __init__(self, filename, mode):<\/em><br \/>\n<em>self.filename = filename<\/em><br \/>\n<em>self.mode = mode<\/em><br \/>\n<em>self.file = None<\/em><\/p>\n<p style=\"text-align: center\"><em>def __enter__(self):<\/em><br \/>\n<em>self.file = open(self.filename, self.mode)<\/em><br \/>\n<em>return self.file<\/em><\/p>\n<p style=\"text-align: center\"><em>def __exit__(self, exc_type, exc_val, exc_tb):<\/em><br \/>\n<em>if self.file:<\/em><br \/>\n<em>self.file.close()<\/em><\/p>\n<p><strong>Usage:<\/strong><\/p>\n<p style=\"text-align: center\"><em>with OpenFile(&#8216;sample.txt&#8217;, &#8216;w&#8217;) as f:<\/em><br \/>\n<em>f.write(&#8216;Hello, world!&#8217;)<\/em><\/p>\n<p><strong>Cleaner Approach: contextlib Module<\/strong><\/p>\n<p>Python provides a simpler way to write context managers using contextlib.contextmanager.<\/p>\n<p style=\"text-align: center\"><em>from contextlib import contextmanager<\/em><\/p>\n<p style=\"text-align: center\"><em>@contextmanager<\/em><br \/>\n<em>def open_file(name, mode):<\/em><br \/>\n<em>f = open(name, mode)<\/em><br \/>\n<em>try:<\/em><br \/>\n<em>yield f<\/em><br \/>\n<em>finally:<\/em><br \/>\n<em>f.close()<\/em><\/p>\n<p><strong>Real-World Use Cases<\/strong><\/p>\n<ul>\n<li>File I\/O (open)<\/li>\n<li>Locking mechanisms (e.g., threading)<\/li>\n<li>Database connections (like with connection: in SQLAlchemy)<\/li>\n<li>Managing resources in testing (setup\/teardown)<\/li>\n<li>Suppressing exceptions or logs (with contextlib.suppress())<\/li>\n<\/ul>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>Context managers manage setup and teardown automatically.<\/li>\n<li>They\u2019re used with the with statement.<\/li>\n<li>Create one using a class (__enter__ \/ __exit__) or with @contextmanager.<\/li>\n<li>Ensure safe handling of files, resources, or operations where cleanup is crucial.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>List comprehensions (advanced) List comprehensions are a powerful and expressive way to create lists in Python using a single line of code. While basic list comprehensions handle simple transformations, advanced list comprehensions allow for more complex logic, including conditional filtering, nested loops, and function application.<\/p>\n","protected":false},"author":1,"featured_media":496,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Intermediate Topics - Python Course<\/title>\n<meta name=\"description\" content=\"Intermediate Python topics enhance your coding skills with efficient, modular, and scalable techniques like decorators, generators, and OOP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Intermediate Topics - Python Course\" \/>\n<meta property=\"og:description\" content=\"Intermediate Python topics enhance your coding skills with efficient, modular, and scalable techniques like decorators, generators, and OOP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/\" \/>\n<meta property=\"og:site_name\" content=\"BUHAVE\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BeYouHave\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/naveedsafdarawan\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-19T11:34:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-20T12:57:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Intermediate-Topics.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Naveed Safdar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Naveed Safdar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/\"},\"author\":{\"name\":\"Naveed Safdar\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\"},\"headline\":\"Intermediate Topics\",\"datePublished\":\"2025-05-19T11:34:34+00:00\",\"dateModified\":\"2025-05-20T12:57:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/\"},\"wordCount\":1326,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Intermediate-Topics.webp\",\"articleSection\":[\"Python Course\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/\",\"name\":\"Intermediate Topics - Python Course\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Intermediate-Topics.webp\",\"datePublished\":\"2025-05-19T11:34:34+00:00\",\"dateModified\":\"2025-05-20T12:57:18+00:00\",\"description\":\"Intermediate Python topics enhance your coding skills with efficient, modular, and scalable techniques like decorators, generators, and OOP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#primaryimage\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Intermediate-Topics.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Intermediate-Topics.webp\",\"width\":1200,\"height\":628,\"caption\":\"Intermediate Topics\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/intermediate-topics\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Course\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/learn\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Intermediate Topics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"name\":\"BUHAVE\",\"description\":\"Courses - Learn Online for Free\",\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/buhave.com\\\/courses\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\",\"name\":\"BUHAVE\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"width\":375,\"height\":75,\"caption\":\"BUHAVE\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/BeYouHave\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/buhave\",\"https:\\\/\\\/www.youtube.com\\\/@buhave\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\",\"name\":\"Naveed Safdar\",\"description\":\"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedsafdar\\\/\",\"https:\\\/\\\/www.facebook.com\\\/naveedsafdarawan\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@naveedsafdar\"],\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/author\\\/naveed-safdar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Intermediate Topics - Python Course","description":"Intermediate Python topics enhance your coding skills with efficient, modular, and scalable techniques like decorators, generators, and OOP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/","og_locale":"en_US","og_type":"article","og_title":"Intermediate Topics - Python Course","og_description":"Intermediate Python topics enhance your coding skills with efficient, modular, and scalable techniques like decorators, generators, and OOP.","og_url":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/","og_site_name":"BUHAVE","article_publisher":"https:\/\/www.facebook.com\/BeYouHave\/","article_author":"https:\/\/www.facebook.com\/naveedsafdarawan\/","article_published_time":"2025-05-19T11:34:34+00:00","article_modified_time":"2025-05-20T12:57:18+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Intermediate-Topics.webp","type":"image\/webp"}],"author":"Naveed Safdar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Naveed Safdar","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#article","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/"},"author":{"name":"Naveed Safdar","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca"},"headline":"Intermediate Topics","datePublished":"2025-05-19T11:34:34+00:00","dateModified":"2025-05-20T12:57:18+00:00","mainEntityOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/"},"wordCount":1326,"commentCount":0,"publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Intermediate-Topics.webp","articleSection":["Python Course"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/","url":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/","name":"Intermediate Topics - Python Course","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/#website"},"primaryImageOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#primaryimage"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Intermediate-Topics.webp","datePublished":"2025-05-19T11:34:34+00:00","dateModified":"2025-05-20T12:57:18+00:00","description":"Intermediate Python topics enhance your coding skills with efficient, modular, and scalable techniques like decorators, generators, and OOP.","breadcrumb":{"@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buhave.com\/courses\/python\/intermediate-topics\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#primaryimage","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Intermediate-Topics.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Intermediate-Topics.webp","width":1200,"height":628,"caption":"Intermediate Topics"},{"@type":"BreadcrumbList","@id":"https:\/\/buhave.com\/courses\/python\/intermediate-topics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Courses","item":"https:\/\/buhave.com\/courses\/"},{"@type":"ListItem","position":2,"name":"Python Course","item":"https:\/\/buhave.com\/courses\/learn\/python\/"},{"@type":"ListItem","position":3,"name":"Intermediate Topics"}]},{"@type":"WebSite","@id":"https:\/\/buhave.com\/courses\/#website","url":"https:\/\/buhave.com\/courses\/","name":"BUHAVE","description":"Courses - Learn Online for Free","publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buhave.com\/courses\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/buhave.com\/courses\/#organization","name":"BUHAVE","url":"https:\/\/buhave.com\/courses\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","width":375,"height":75,"caption":"BUHAVE"},"image":{"@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BeYouHave\/","https:\/\/www.linkedin.com\/company\/buhave","https:\/\/www.youtube.com\/@buhave"]},{"@type":"Person","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca","name":"Naveed Safdar","description":"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.","sameAs":["https:\/\/www.linkedin.com\/in\/naveedsafdar\/","https:\/\/www.facebook.com\/naveedsafdarawan\/","https:\/\/www.youtube.com\/@naveedsafdar"],"url":"https:\/\/buhave.com\/courses\/author\/naveed-safdar\/"}]}},"_links":{"self":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/comments?post=495"}],"version-history":[{"count":2,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/495\/revisions"}],"predecessor-version":[{"id":764,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/495\/revisions\/764"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media\/496"}],"wp:attachment":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media?parent=495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/categories?post=495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/tags?post=495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}