{"id":21343,"date":"2025-02-17T15:51:18","date_gmt":"2025-02-17T15:51:18","guid":{"rendered":"https:\/\/codegnan.com\/?p=21343"},"modified":"2026-05-26T10:27:39","modified_gmt":"2026-05-26T10:27:39","slug":"python-interview-questions","status":"publish","type":"post","link":"https:\/\/codegnan.com\/python-interview-questions\/","title":{"rendered":"37 Python Interview Questions to Crack Any Interview in 2026"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">Preparing for a Python interview in 2026?\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Whether you&#8217;re a fresher or an experienced professional, having the right knowledge is key to success.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">At Codegnan, we help you master Python with hands-on training and real-world projects. With 30,000+ students trained and 1,250+ hiring partners, we know what it takes to land a tech job.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In this guide, we cover the most important Python interview questions from freshers to advanced levels.<\/p>\r\n\r\n\r\n\r\n<h2 id=\"h-python-interview-questions-for-freshers\" class=\"wp-block-heading\"><strong>Python interview questions for freshers<\/strong><\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>\ud83d\udca1 Looking to upskill your Python skills? Explore our training courses:<\/strong><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/codegnan.com\/academy\/online-python-course\/\">Online Python programming course<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/codegnan.com\/python-training-in-bangalore\/\">Python course in Bangalore<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/codegnan.com\/python-training-in-vijayawada\/\">Python course in Vijayawada<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/codegnan.com\/python-training-course-in-hyderabad\/\">Learn Python in Hyderabad<\/a><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 id=\"h-1-what-is-python-and-what-are-its-key-features\" class=\"wp-block-heading\">1. What is Python, and what are its key features?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python is a high-level, interpreted programming language known for its simplicity and readability.\u00a0 It supports multiple programming paradigms, such as procedural, object-oriented, and functional programming. Python is widely used in web development, data science, automation, AI, and more.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Key Features:<\/strong><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><strong>Easy to Learn<\/strong> \u2013 Simple syntax like English.<\/li>\r\n\r\n\r\n\r\n<li><strong>Interpreted<\/strong> \u2013 Executes code line by line.<\/li>\r\n\r\n\r\n\r\n<li><strong>Dynamically Typed<\/strong> \u2013 No need to declare variable types.<\/li>\r\n\r\n\r\n\r\n<li><strong>Cross-Platform<\/strong> \u2013 Runs on Windows, Mac, and Linux.<\/li>\r\n\r\n\r\n\r\n<li><strong>Extensive Libraries<\/strong> \u2013 Supports NumPy, Pandas, TensorFlow, etc.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 id=\"h-2-explain-the-difference-between-python-lists-and-tuples\" class=\"wp-block-heading\">2. Explain the difference between Python lists and tuples.<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Lists and tuples both store multiple values, but they have key differences:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<tbody>\r\n<tr>\r\n<td>Lists<\/td>\r\n<td>Tuples<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Lists are mutable, meaning you can change, add, or remove elements after creation.<\/td>\r\n<td>Tuples are immutable, meaning that once created, their values cannot be changed.<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Lists use square brackets [ ]<\/td>\r\n<td>Tuples use parentheses ( )<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Lists are little slower in execution due to constant changes of data<\/td>\r\n<td>Tuples are faster than lists because they don\u2019t allow changes<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Use lists when data needs to be modified.<\/td>\r\n<td>Use tuples when data should remain constant<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<h3 id=\"h-3-what-is-init-in-python\" class=\"wp-block-heading\">3. What is __init__() in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">__init__() in Python is a special method (also called a constructor) in Python classes. It runs automatically when an object is created. It helps initialise object attributes. When you create an object from a class, Python automatically calls __init__() to prepare the object with the values you provide.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>class Person:\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __init__(self, name, age):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.name = name\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.age = age\r\n\r\nperson = Person(\"Alice\", 30)\r\n\r\nprint(person.name, person.age)\u00a0 # Output: Alice 30<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXeQ4Xmqk4VvcqxTk0RRSER8aX0B_RZgYbMi1QjOqAzDG39Qw0DlrJ5V0_A5P4cQszuwP65xou3Oij0U2D2wehnmGeTyzXVxtiXBMTNWFR3hPoFamPHVKjEON9PL_l18PMDbw43Quw?key=aGdfE8RTL768bxmWFpNabXTQ\" alt=\"\" \/><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The __init__() method streamlines object creation by automatically setting attributes when an object is instantiated. This avoids the need for separate setup calls and keeps the code cleaner.\u00a0<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-4-what-are-mutable-and-immutable-data-types-in-python\" class=\"wp-block-heading\">4. What are mutable and immutable data types in Python?<\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Mutable data types can change after creation. Example: Lists, Dictionaries, Sets.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">For example,<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>my_list = [1, 2, 3]\r\nmy_list.append(4)\u00a0 # List changes\r\n\r\nprint(my_list)<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXeNz4O39JyI1RbX1DiN_yNS9H8TcLM60Ywl5hwtjjAqv-eFVz1h7rmz50kmk3LaYPZtrnQpedKxdRXIzfVkze9vg5xb59KxYf1kwvzKr-esTqe_RXTfsZkuyCZzDWHJstDhpyTh?key=aGdfE8RTL768bxmWFpNabXTQ\" alt=\"\" \/><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: This example showcases mutable objects that can be changed.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Immutable data types cannot change after creation. Example: Tuples, Strings, Integers, Floats.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">text = &#8220;hello&#8221;<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">text[0] = &#8220;H\u201d<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXc7KJFqZHqd9IL9KWXBRrv8wDjs_zgY6peeTCEglIyEOoHSinThW3XQbiU4U5e8jxUL-mn0-Nx3mgrUsbtTi_hQTIFe39IIkHhSxzcfP9kuZ9eg8jVvcu6gGMfXzWRQia2p-tsH8w?key=aGdfE8RTL768bxmWFpNabXTQ\" alt=\"\" \/><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: This example showcases Immutable objects remain the same after creation.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-5-how-do-list-dictionary-and-tuple-comprehensions-work-provide-examples\" class=\"wp-block-heading\">5. How do list, dictionary, and tuple comprehensions work? Provide examples.<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Comprehensions in Python offer a compact way to generate new collections from existing ones. Comprehensions simplify your code by replacing lengthy loops with concise expressions that are easy to read.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>List comprehensions create lists using a single line that includes an expression, a loop, and an optional condition.\u00a0<\/li>\r\n\r\n\r\n\r\n<li>Dictionary comprehensions use a similar syntax to build dictionaries by defining key-value pairs.\u00a0<\/li>\r\n\r\n\r\n\r\n<li>Although there is no direct tuple comprehension, you can create a generator expression and convert it to a tuple.\u00a0<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples :<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code># List comprehension\r\nsquares = [x**2 for x in range(5)]\r\nprint(squares)\u00a0 # [0, 1, 4, 9, 16]\r\n\r\n# Dictionary comprehension\r\n\r\nsquare_dict = {x: x**2 for x in range(5)}\r\n\r\nprint(square_dict)\u00a0 # {0: 0, 1: 1, 2: 4, 3: 9, 4: 16}\r\n\r\n# Tuple comprehension (using generator expression)\r\n\r\nsquare_tuple = tuple(x**2 for x in range(5))\r\n\r\nprint(square_tuple)\u00a0 # (0, 1, 4, 9, 16)<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The list comprehension [x**2 for x in range(5)] loops through numbers 0-4 and squares each.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The dictionary comprehension {x: x**2 for x in range(5)} creates key-value pairs.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Since () creates a generator, we use tuple() to get a tuple.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-6-what-is-the-global-interpreter-lock-gil-in-python\" class=\"wp-block-heading\">6. What is the Global Interpreter Lock (GIL) in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The Global Interpreter Lock (GIL) is a mechanism in CPython that ensures only one thread executes Python bytecode at a time. This means that even on multi-core processors, Python threads do not run in parallel for CPU-bound tasks. However, GIL does not affect multi-processing or I\/O-bound tasks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import threading\r\n\r\ncounter = 0\r\n\r\ndef increment():\r\n\r\n\u00a0\u00a0\u00a0\u00a0global counter\r\n\r\n\u00a0\u00a0\u00a0\u00a0for _ in range(1000000):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0counter += 1\r\n\r\nt1 = threading.Thread(target=increment)\r\n\r\nt2 = threading.Thread(target=increment)\r\n\r\nt1.start()\r\n\r\nt2.start()\r\n\r\nt1.join()\r\n\r\nt2.join()\r\n\r\nprint(\"Counter:\", counter)\u00a0 # Output may be less than 2000000 due to GIL<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Python threads don\u2019t run in true parallel because of the GIL. The threads take turns holding the GIL, which can cause race conditions and slow down multi-threaded programs. To achieve true parallelism, use the multiprocessing module instead.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-7-what-are-python-s-built-in-data-types\" class=\"wp-block-heading\">7. What are Python\u2019s built-in data types?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python provides several built-in data types to store different kinds of values:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Numeric types: int, float, complex<\/li>\r\n\r\n\r\n\r\n<li>Sequence types: list, tuple, range<\/li>\r\n\r\n\r\n\r\n<li>Text type: str<\/li>\r\n\r\n\r\n\r\n<li>Set types: set, frozenset<\/li>\r\n\r\n\r\n\r\n<li>Mapping type: dict<\/li>\r\n\r\n\r\n\r\n<li>Boolean type: bool<\/li>\r\n\r\n\r\n\r\n<li>Binary types: bytes, bytearray, memoryview<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>x = 10 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # int\r\n\r\ny = 3.14\u00a0 \u00a0 \u00a0 \u00a0 # float\r\n\r\nz = \"Hello\" \u00a0 \u00a0 # str\r\n\r\nl = [1, 2, 3] \u00a0 # list\r\n\r\nt = (4, 5, 6) \u00a0 # tuple\r\n\r\ns = {7, 8, 9} \u00a0 # set\r\n\r\nd = {\"a\": 1}\u00a0 \u00a0 # dict\r\n\r\nb = True\u00a0 \u00a0 \u00a0 \u00a0 # bool\r\n\r\nprint(type(x), type(y), type(z), type(l), type(t), type(s), type(d), type(b))<\/code><\/pre>\r\n\r\n\r\n\r\n<h3 id=\"h-8-how-does-python-handle-type-conversion-casting\" class=\"wp-block-heading\">8. How does Python handle type conversion (casting)?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python allows automatic (implicit) and manual (explicit) type conversion. Implicit conversion happens when Python converts a smaller type to a larger type, while explicit conversion (casting) is done using built-in functions like int(), float(), str(), etc.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code># Implicit conversion\r\n\r\na = 5\u00a0 \u00a0 # int\r\n\r\nb = 2.5\u00a0 # float\r\n\r\nc = a + b\u00a0 # float\r\n\r\nprint(c, type(c))\u00a0 # Output: 7.5 &lt;class 'float'&gt;\r\n\r\n# Explicit conversion\r\n\r\nx = \"10\"\r\n\r\ny = int(x) + 5\r\n\r\nprint(y, type(y))\u00a0 # Output: 15 &lt;class 'int'&gt;<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Python avoids data loss by automatically converting types where possible. However, explicit conversion is needed when converting between incompatible types like str to int. You must check compatibility before casting to avoid errors.<\/p>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li>What is the difference between is and == in Python?<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The \u201cis\u201d operator checks whether two variables refer to the same object in memory, while \u201c==\u201d checks whether their values are equal.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>a = [1, 2, 3]\r\n\r\nb = a\r\n\r\nc = [1, 2, 3]\r\n\r\nprint(a == c)\u00a0 # True (values are the same)\r\n\r\nprint(a is c)\u00a0 # False (different memory locations)\r\n\r\nprint(a is b)\u00a0 # True (same memory location)<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Even though a and c have the same values, they are stored in different locations in memory. The \u201cis\u201d operator checks memory identity, while \u201c==\u201d checks value equality. This is important when dealing with mutable objects like lists and dictionaries.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-9-how-can-you-read-and-write-files-in-python\" class=\"wp-block-heading\">9. How can you read and write files in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python provides the open() function to read and write files. It supports different modes:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>&#8220;r&#8221; \u2192 Read (default)<\/li>\r\n\r\n\r\n\r\n<li>&#8220;w&#8221; \u2192 Write (overwrites file)<\/li>\r\n\r\n\r\n\r\n<li>&#8220;a&#8221; \u2192 Append (adds to existing content)<\/li>\r\n\r\n\r\n\r\n<li>&#8220;rb&#8221;, &#8220;wb&#8221; \u2192 Read\/write in binary mode<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples :<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>Writing to a File\r\n\r\nwith open(\"example.txt\", \"w\") as file:\r\n\r\n\u00a0\u00a0\u00a0\u00a0file.write(\"Hello, Python!\")\r\n\r\nReading from a File\r\n\r\nwith open(\"example.txt\", \"r\") as file:\r\n\r\n\u00a0\u00a0\u00a0\u00a0content = file.read()\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(content)\u00a0 # Output: Hello, Python!<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The \u201cwith\u201d statement ensures the file closes automatically. The &#8220;w&#8221; mode overwrites existing content, and the &#8220;r&#8221; mode reads the file\u2019s content.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>PYTHON RESOURCES TO HELP IN YOUR CAREER:<\/strong><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/codegnan.com\/python-course-syllabus\/\">Python course syllabus: course fees, duration, and eligibility<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/codegnan.com\/python-projects\/\">Python projects for freshers and experienced students<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/codegnan.com\/python-career-paths\/\">In-demand Python career paths\u00a0<\/a><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 id=\"h-python-interview-questions-for-intermediate-nbsp\" class=\"wp-block-heading\"><strong>Python interview questions for Intermediate\u00a0<\/strong><\/h2>\r\n\r\n\r\n\r\n<h3 id=\"h-10-explain-common-searching-and-graph-traversal-algorithms-in-python\" class=\"wp-block-heading\">10. Explain common searching and graph traversal algorithms in Python.<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The common searching algorithms in Python include Linear Search and Binary Search, and the common graph traversal algorithms are Depth-First Search (DFS) and Breadth-First Search (BFS).<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><strong>Linear Search<\/strong> checks every element one by one and works on unsorted lists.<\/li>\r\n\r\n\r\n\r\n<li><strong>Binary Search<\/strong> works on sorted lists by dividing the list in half repeatedly.<\/li>\r\n\r\n\r\n\r\n<li><strong>DFS<\/strong> explores a graph by going deep along one branch before backtracking.<\/li>\r\n\r\n\r\n\r\n<li><strong>BFS<\/strong> explores all neighbours of a node before moving deeper.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples :<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>def binary_search(arr, target):\r\n\r\n\u00a0\u00a0\u00a0\u00a0left, right = 0, len(arr) - 1\r\n\r\n\u00a0\u00a0\u00a0\u00a0while left &lt;= right:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mid = (left + right) \/\/ 2\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if arr[mid] == target:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return mid\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0elif arr[mid] &lt; target:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0left = mid + 1\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0right = mid - 1\r\n\r\n\u00a0\u00a0\u00a0\u00a0return -1\r\n\r\narr = [1, 3, 5, 7, 9, 11]\r\n\r\nprint(binary_search(arr, 5))\u00a0 # Output: 2<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Binary search only works on sorted lists. It repeatedly divides the list in half, checking if the middle element matches the target. If not, it narrows the search to either the left or right half, making it O(log n) in efficiency.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-11-what-is-a-keyerror-in-python-and-how-can-you-handle-it\" class=\"wp-block-heading\">11. What is a KeyError in Python, and how can you handle it?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A KeyError occurs when you try to access a dictionary key that doesn\u2019t exist. This often happens when fetching values from dictionaries without checking if the key exists. You can prevent it using .get() or a try-except block.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>student = {\"name\": \"Alice\", \"age\": 12}\r\n\r\nprint(student[\"grade\"])\u00a0 # Raises KeyError\r\n\r\n# Handling with .get()\r\n\r\nprint(student.get(\"grade\", \"Not available\"))\u00a0 # Output: Not available\r\n\r\n# Handling with try-except\r\n\r\ntry:\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(student[\"grade\"])\r\n\r\nexcept KeyError:\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(\"Key not found!\")<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: When you access student[&#8220;grade&#8221;], Python throws a KeyError because &#8220;grade&#8221; is not in the dictionary. Using get() prevents this by returning a default value. The try-except block catches the error and lets the program continue running without crashing.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-12-how-does-python-manage-memory-and-what-is-the-role-of-garbage-collection\" class=\"wp-block-heading\">12. How does Python manage memory, and what is the role of garbage collection?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python manages memory automatically using reference counting and garbage collection. When an object has no references, Python\u2019s garbage collector (GC) deletes it to free up memory. The \u201cgc\u201d module can control and manually trigger garbage collection.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import gc\r\n\r\nclass Demo:\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __del__(self):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(\"Object deleted\")\r\n\r\nobj = Demo()\r\n\r\ndel obj\u00a0 # Deletes the object immediately\r\n\r\ngc.collect()\u00a0 # Manually trigger garbage collection<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: When del obj runs, Python removes the object if no references exist. The __del__() method shows when deletion happens. The gc.collect() function forces Python to clean up unused objects. Python&#8217;s garbage collector prevents memory leaks by removing objects that are no longer used.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-13-what-is-the-difference-between-shallow-and-deep-copy-in-python\" class=\"wp-block-heading\">13. What is the difference between shallow and deep copy in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The difference between shallow and deep copy in Python is-<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A shallow copy creates a new object, but copies references to the original elements, meaning changes to mutable elements affect both copies. It\u2019s made using copy.copy().<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A deep copy creates a new object and recursively copies all elements, ensuring complete independence from the original. It\u2019s made using copy.deepcopy().<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import copy\r\n\r\noriginal = [[1, 2, 3], [4, 5, 6]]\r\n\r\nshallow = copy.copy(original)\r\n\r\ndeep = copy.deepcopy(original)\r\n\r\nshallow[0][0] = 99\u00a0 # Affects both original and shallow\r\n\r\ndeep[1][1] = 88\u00a0 # Affects only deep copy\r\n\r\nprint(original)\u00a0 # Output: [[99, 2, 3], [4, 5, 6]]\r\n\r\nprint(deep)\u00a0 # Output: [[1, 2, 3], [4, 88, 6]]<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The copy.copy() creates a shallow copy where only references to nested lists are copied. When changes are made on the nested elements it reflects in both original and copy. The copy.deepcopy() creates a completely new copy, so modifying it does not affect the original.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-14-how-can-you-use-python-s-collections-module-to-simplify-coding\" class=\"wp-block-heading\">14. How can you use Python\u2019s collections module to simplify coding?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The collections module provides optimised alternatives to built-in data structures, making code more readable and efficient. It includes Counter, defaultdict, OrderedDict, deque, and namedtuple.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>from collections import Counter\r\n\r\nwords = [\"apple\", \"banana\", \"apple\", \"orange\", \"banana\", \"apple\"]\r\n\r\ncount = Counter(words)\r\n\r\nprint(count)\u00a0 # Output: Counter({'apple': 3, 'banana': 2, 'orange': 1})<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The Counter counts how often each item appears in a list, saving effort compared to writing a loop. Instead of manually tracking counts, Counter does it in one line. Other useful tools include deque for efficient queue operations and defaultdict for avoiding KeyErrors with missing dictionary keys.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-15-what-is-the-difference-between-args-and-kwargs-in-function-definitions\" class=\"wp-block-heading\">15. What is the difference between args and kwargs in function definitions?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">*args allows a function to accept any number of positional arguments, while **kwargs allows it to accept any number of keyword arguments (key-value pairs).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>def greet(*args, **kwargs):\r\n\r\n\u00a0\u00a0\u00a0\u00a0for name in args:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f\"Hello, {name}!\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0for key, value in kwargs.items():\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f\"{key}: {value}\")\r\n\r\ngreet(\"Alice\", \"Bob\", age=25, country=\"USA\")<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: In the example, *args collects &#8220;Alice&#8221; and &#8220;Bob&#8221;, treating them as a tuple. **kwargs collects age=25 and country=&#8221;USA&#8221;, treating them as a dictionary. *args is useful for handling multiple values without defining them one by one, while **kwargs helps when you need named parameters.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-16-explain-python-s-exception-handling-with-an-example\" class=\"wp-block-heading\">16. Explain Python\u2019s exception handling with an example.<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python exception handling mechanism helps manage runtime errors using try, except, finally, and else. This prevents crashes and helps manage errors gracefully.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>try:\r\n\r\n\u00a0\u00a0\u00a0\u00a0result = 10 \/ 0\u00a0\u00a0\r\n\r\nexcept ZeroDivisionError:\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(\"Error: Cannot divide by zero!\")\u00a0\u00a0\r\n\r\nelse:\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(\"Division successful.\")\u00a0\u00a0\r\n\r\nfinally:\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(\"Execution completed.\")<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The try block runs the code, and if an error occurs, it moves to the except block. If the user enters 0, the ZeroDivisionError block runs. If a non-number is entered, ValueError is handled. The finally block runs no matter what, ensuring cleanup or a final message.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-17-what-are-python-generators-and-how-do-they-differ-from-iterators\" class=\"wp-block-heading\">17. What are Python generators, and how do they differ from iterators?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In Python, generators are special functions that allow you to create iterators in a simple way. They use the yield keyword to produce a sequence of values lazily, meaning they generate each value only when needed, which saves memory.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">An iterator, on the other hand, is an object that implements the __iter__() and __next__() methods, allowing you to traverse through all the values.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">While all generators are iterators, not all iterators are generators. Generators provide a convenient way to implement the iterator protocol without the need to write a separate class with __iter__() and __next__() methods.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>def count_up_to(n):\r\n\r\n\u00a0\u00a0\u00a0\u00a0count = 1\r\n\r\n\u00a0\u00a0\u00a0\u00a0while count &lt;= n:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0yield count\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0count += 1\r\n\r\ngen = count_up_to(5)\r\n\r\nprint(next(gen))\u00a0 # Output: 1\r\n\r\nprint(next(gen))\u00a0 # Output: 2<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The count_up_to() function generates numbers up to n one at a time. Unlike lists, which store all values, generators pause execution after yield, resuming when the next() is called. This saves memory when working with large datasets.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-18-what-is-the-purpose-of-the-zip-function-in-python\" class=\"wp-block-heading\">18. What is the purpose of the zip() function in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The zip() function combines multiple iterable (like lists or tuples) element-wise into pairs, triplets, or more. It stops when the shortest iterable is exhausted. This function is useful when you need to process multiple lists together in a loop.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>names = [\"Alice\", \"Bob\", \"Charlie\"]\r\n\r\nscores = [90, 85, 95]\r\n\r\nzipped = zip(names, scores)\r\n\r\nprint(list(zipped))\u00a0 # Output: [('Alice', 90), ('Bob', 85), ('Charlie', 95)]<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The zip() function pairs elements from names and scores, creating tuples like (&#8220;Alice&#8221;, 90). If the lists have different lengths, zip() stops at the shortest one. This is useful for processing related data together, like combining student names with scores.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-19-what-are-lambda-functions-and-how-are-they-used-in-python\" class=\"wp-block-heading\">19. What are lambda functions, and how are they used in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Lambda functions in Python are small, anonymous functions defined using the lambda keyword. They can have multiple arguments but only one expression, which is evaluated and returned. They are useful when you need short, throwaway functions without defining a full function using def.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Examples:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code># A lambda function that adds 5 to a number\r\n\r\nadd_five = lambda x: x + 5\u00a0\u00a0\r\n\r\nprint(add_five(10))\u00a0 # Output: 15\r\n\r\n\ud83d\udca1 Explanation: Here, lambda x: x + 5 creates a function that takes x as input and returns x + 5.\r\n\r\nLambda functions are commonly used with functions like map(), filter(), and sorted().\r\n\r\nExample:\r\n\r\nnumbers = [1, 2, 3, 4]\u00a0\u00a0\r\n\r\nsquared = list(map(lambda x: x**2, numbers))\u00a0\u00a0\r\n\r\nprint(squared)\u00a0 # Output: [1, 4, 9, 16]<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Here, lambda x: x**2 squares each number in the numbers list. map() applies this function to all elements. Lambda functions make the code shorter and cleaner compared to defining a separate function.<\/p>\r\n\r\n\r\n\r\n<h2 id=\"h-python-interview-questions-for-experienced-candidates-nbsp\" class=\"wp-block-heading\"><strong>Python Interview Questions for Experienced Candidates\u00a0<\/strong><\/h2>\r\n\r\n\r\n\r\n<h3 id=\"h-20-what-is-monkey-patching-in-python\" class=\"wp-block-heading\">20. What is monkey patching in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Monkey patching is a way to change or modify a module or class at runtime without altering its original code. It allows us to override methods dynamically, but it should be used carefully as it can lead to unexpected behaviour.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>class Animal:\r\n\r\n\u00a0\u00a0\u00a0\u00a0def sound(self):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return \"Some sound\"\r\n\r\n# Define a new function to replace the existing method\r\n\r\ndef new_sound():\r\n\r\n\u00a0\u00a0\u00a0\u00a0return \"Meow\"\r\n\r\n# Apply monkey patch\r\n\r\nAnimal.sound = new_sound\u00a0\u00a0\r\n\r\n# Test the patched class\r\n\r\na = Animal()\r\n\r\nprint(a.sound())\u00a0 # Output: Meow<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: In this example, the Animal class originally had a sound method that returned &#8220;Some sound.&#8221; However, using monkey patching, we replaced it with new_sound, which returns &#8220;Meow.&#8221; This shows how we can modify existing classes dynamically. However, using monkey patching without proper control can lead to difficult debugging and maintenance issues.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-20-how-does-python-with-statement-work\" class=\"wp-block-heading\">20. How does Python with statement work?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The with statement simplifies resource management by ensuring that files or connections are properly closed after use. It is commonly used when working with files, sockets, or database connections to prevent resource leaks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">with open(&#8220;example.txt&#8221;, &#8220;w&#8221;) as file:<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0\u00a0\u00a0\u00a0file.write(&#8220;Hello, World!&#8221;)\u00a0 # File is automatically closed after this block<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: In this example, the with statement opens a file named &#8220;example.txt&#8221; in write mode. Once the block of code inside with is executed, Python automatically closes the file, even if an error occurs. This prevents issues like file corruption or memory leaks, making code cleaner and more reliable.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-21-why-would-you-use-else-in-a-try-except-construct\" class=\"wp-block-heading\">21. Why would you use else in a try\/except construct?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The else block in a try\/except construct is used when no exceptions occur. It ensures that code inside else runs only if the try block executes successfully, keeping error-handling separate from normal execution.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>try:\r\n\r\n\u00a0\u00a0\u00a0\u00a0number = int(input(\"Enter a number: \"))\r\n\r\nexcept ValueError:\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(\"Invalid input! Please enter a number.\")\r\n\r\nelse:\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(f\"You entered {number}, which is a valid number.\")<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Here, if the user enters a valid number, the else block executes and prints the entered number. If an exception (ValueError) occurs, the except block runs instead. This helps in writing clean, structured error-handling code.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-22-what-are-python-decorators-and-how-do-they-work\" class=\"wp-block-heading\">22. What are Python decorators, and how do they work?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A decorator in Python is a function that modifies another function without changing its actual code. It allows adding extra functionality like logging, authentication, or timing execution.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>def greet_decorator(func):\r\n\r\n\u00a0\u00a0\u00a0\u00a0def wrapper():\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(\"Hello!\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0func()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(\"Goodbye!\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0return wrapper\r\n\r\n@greet_decorator\r\n\r\ndef say_name():\r\n\r\n\u00a0\u00a0\u00a0\u00a0print(\"My name is John.\")\r\n\r\nsay_name()<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Here, greet_decorator takes say_name() as input and modifies it. When say_name() is called, it prints &#8220;Hello!&#8221; first, then the function output, and finally &#8220;Goodbye!&#8221;. This is useful for adding functionality without modifying existing functions directly.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-23-what-are-context-managers-in-python-and-how-can-you-create-one\" class=\"wp-block-heading\">23. What are context managers in Python, and how can you create one?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Context managers in Python handle resource management, like opening and closing files automatically. The with statement is used to ensure that resources are released properly after use. You can create a context manager using a class with __enter__() and __exit__() methods or by using the contextlib module\u2019s contextmanager decorator.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>class FileManager:\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __init__(self, filename, mode):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.file = open(filename, mode)\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __enter__(self):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return self.file\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __exit__(self, exc_type, exc_value, traceback):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.file.close()\r\n\r\nwith FileManager(\"example.txt\", \"w\") as file:\r\n\r\n\u00a0\u00a0\u00a0\u00a0file.write(\"Hello, Context Manager!\")<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The FileManager class opens a file when __enter__() is called and returns the file object. The __exit__() method ensures the file closes automatically, even if an error occurs. The with statement simplifies resource management, reducing errors like forgetting to close files.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-24-what-are-metaclasses-and-how-do-they-differ-from-regular-classes\" class=\"wp-block-heading\">24. What are metaclasses, and how do they differ from regular classes?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A metaclass in Python is a class that defines how other classes behave. While regular classes create objects, metaclasses create and modify classes themselves.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>class Meta(type):\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __new__(cls, name, bases, dct):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f\"Creating class: {name}\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return super().__new__(cls, name, bases, dct)\r\n\r\nclass MyClass(metaclass=Meta):\r\n\r\n\u00a0\u00a0\u00a0\u00a0pass<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Meta is a metaclass because it inherits from type. When MyClass is defined, Meta controls its creation. The __new__ method prints a message, showing how the metaclass customizes class creation.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-25-how-would-you-implement-an-lru-cache-in-python\" class=\"wp-block-heading\">25. How would you implement an LRU cache in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">An LRU (Least Recently Used) cache removes the least recently used items when it reaches its maximum size. In Python, we can use the functools.lru_cache decorator or implement it manually using OrderedDict from collections.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>from collections import OrderedDict\r\n\r\nclass LRUCache:\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __init__(self, capacity: int):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.cache = OrderedDict()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.capacity = capacity\r\n\r\n\u00a0\u00a0\u00a0\u00a0def get(self, key: int):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if key not in self.cache:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return -1\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.cache.move_to_end(key)\u00a0 # Mark as recently used\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return self.cache[key]\r\n\r\n\u00a0\u00a0\u00a0\u00a0def put(self, key: int, value: int):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if key in self.cache:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.cache.move_to_end(key)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0elif len(self.cache) &gt;= self.capacity:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.cache.popitem(last=False)\u00a0 # Remove LRU item\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.cache[key] = value\r\n\r\n# Usage\r\n\r\nlru = LRUCache(2)\r\n\r\nlru.put(1, \"A\")\r\n\r\nlru.put(2, \"B\")\r\n\r\nprint(lru.get(1))\u00a0 # Output: \"A\"\r\n\r\nlru.put(3, \"C\")\u00a0 \u00a0 # Removes key 2 (least recently used)\r\n\r\nprint(lru.get(2))\u00a0 # Output: -1<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: An OrderedDict maintains the order of inserted items. When accessing a key using get(), we move it to the end to mark it as recently used. If the cache exceeds its capacity, the popitem(last=False) method removes the least recently used item. This ensures our cache stays within the limit while keeping the most recent items accessible.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-26-how-can-you-optimize-python-code-for-performance\" class=\"wp-block-heading\">26. How can you optimize Python code for performance?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can optimize Python code by using efficient data structures like dictionaries and sets, avoiding unnecessary loops, and using built-in functions. Anyone can use list comprehensions instead of loops, and prefer generators for large data processing.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The multiprocessing and threading modules help with parallel execution. Profiling tools like cProfile can identify slow parts of your code. You can use external libraries like NumPy to speed up numerical computations.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code># Using list comprehension instead of a loop\u00a0\u00a0\r\n\r\nsquares = [x**2 for x in range(10)]\u00a0\u00a0\r\n\r\nprint(squares)<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation:\u00a0 In this example, we generate squares of numbers from 0 to 9 in a single line, making it both readable and efficient.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-27-how-do-you-implement-multithreading-and-multiprocessing-in-python\" class=\"wp-block-heading\">27. How do you implement multithreading and multiprocessing in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python provides two modules for handling multithreading and multiprocessing:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>threading module: It is used for multithreading, where multiple threads share the same memory and run within a single process. \u201cthreading\u201d module is best for I\/O-bound tasks like downloading files, reading from a database, or handling user inputs.<\/li>\r\n\r\n\r\n\r\n<li>multiprocessing module: It is used for multiprocessing, where separate processes run independently with their own memory. \u201cmultiprocessing\u201d module is best for CPU-intensive tasks like data processing, image processing, and computations.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example :<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import threading\r\n\r\ndef print_numbers():\r\n\r\n\u00a0\u00a0\u00a0\u00a0for i in range(5):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f\"Number: {i}\")\r\n\r\n# Creating a thread\r\n\r\nthread = threading.Thread(target=print_numbers)\r\n\r\n# Starting the thread\r\n\r\nthread.start()\r\n\r\n# Waiting for the thread to finish\r\n\r\nthread.join()\r\n\r\nprint(\"Thread execution completed\")<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The threading.Thread(target=print_numbers) creates a new thread to execute the print_numbers function. The start() begins the thread execution,\u00a0 and join() ensures the main program waits until the thread finishes.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-28-explain-how-you-would-design-a-python-based-web-scraper\" class=\"wp-block-heading\">28. Explain how you would design a Python-based web scraper.<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">To design a Python-based web scraper, first, you can choose a library like BeautifulSoup or Scrapy to extract data from websites. Then, use requests to fetch HTML pages and BeautifulSoup to parse them. You can identify the structure of the target webpage using browser developer tools (Inspect Element).\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Then, extract data by finding HTML elements (like &lt;div&gt;, &lt;span&gt;, or &lt;table&gt;) and finally store the results in a file (CSV, JSON) or database. You can handle errors like timeouts and blockages using headers, proxies, or delays.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import requests\u00a0\u00a0\r\n\r\nfrom bs4 import BeautifulSoup\u00a0\u00a0\r\n\r\nurl = \"https:\/\/example.com\"\u00a0\u00a0\r\n\r\nheaders = {\"User-Agent\": \"Mozilla\/5.0\"}\u00a0 # Prevent blocking\r\n\r\nresponse = requests.get(url, headers=headers)\u00a0\u00a0\r\n\r\nsoup = BeautifulSoup(response.text, \"html.parser\")\u00a0\u00a0\r\n\r\ntitles = soup.find_all(\"h2\")\u00a0\u00a0\r\n\r\nfor title in titles:\u00a0\u00a0\r\n\r\nprint(title.text)<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: This script sends a request to example.com and gets its HTML content. It uses BeautifulSoup to parse the page and extract all &lt;h2&gt; elements (titles). The headers prevent detection as a bot. This is useful for gathering information like product prices, news headlines, or job listings.<\/p>\r\n\r\n\r\n\r\n<h2 id=\"h-bonus-python-interview-questions\" class=\"wp-block-heading\"><strong>Bonus Python Interview Questions<\/strong><\/h2>\r\n\r\n\r\n\r\n<h3 id=\"h-29-what-are-the-differences-between-python-2-and-python-3\" class=\"wp-block-heading\">29. What are the differences between Python 2 and Python 3?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python 2 and Python 3 have several key differences. Python 2 is outdated and no longer maintained, while Python 3 is the present and future of Python.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">One major difference is how they handle print. In Python 2, print is a statement (print &#8220;Hello&#8221;), whereas in Python 3, it is a function (print(&#8220;Hello&#8221;)).\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Another key difference is integer division. In Python 2, dividing integers (5\/2) gives 2, while in Python 3, it gives 2.5 due to floating-point division. Python 3 also improves Unicode handling, making string management easier.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-30-how-do-you-merge-two-dictionaries-in-python\" class=\"wp-block-heading\">30. How do you merge two dictionaries in Python?<\/h3>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\" start=\"31\">\r\n<li>\u00a0<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In Python, you can merge two dictionaries using the update() method or the | operator (introduced in Python 3.9). These methods combine key-value pairs from both dictionaries. If there are duplicate keys, the values in the second dictionary overwrite those in the first dictionary.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code># Using update() method\r\n\r\ndict1 = {\"a\": 1, \"b\": 2}\r\n\r\ndict2 = {\"b\": 3, \"c\": 4}\r\n\r\ndict1.update(dict2)\r\n\r\nprint(dict1)\u00a0 # {'a': 1, 'b': 3, 'c': 4}\r\n\r\n# Using | operator (Python 3.9+)\r\n\r\nmerged_dict = dict1 | dict2\r\n\r\nprint(merged_dict)\u00a0 # {'a': 1, 'b': 3, 'c': 4}<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The update() method modifies the original dictionary by adding or updating key-value pairs. The | operator creates a new dictionary without changing the original ones. The second dictionary\u2019s values overwrite duplicate keys from the first dictionary. These methods help when combining data from multiple sources.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-30-explain-the-difference-between-deep-copy-and-shallow-copy-in-python\" class=\"wp-block-heading\">30. Explain the difference between deep copy and shallow copy in Python.<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A shallow copy creates a new object, but it only copies references to the original elements. A deep copy, however, creates a completely independent copy of the original object, including nested structures. This means that modifying a deep copy does not affect the original object, but modifying a shallow copy might.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import copy\r\n\r\n# Original list with a nested list\r\n\r\noriginal = [[1, 2], [3, 4]]\r\n\r\n# Shallow copy\r\n\r\nshallow = copy.copy(original)\r\n\r\n# Deep copy\r\n\r\ndeep = copy.deepcopy(original)\r\n\r\n# Modify the nested list in the original\r\n\r\noriginal[0][0] = 99\r\n\r\nprint(shallow)\u00a0 # [[99, 2], [3, 4]] (affected)\r\n\r\nprint(deep) \u00a0 \u00a0 # [[1, 2], [3, 4]] (not affected)<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: In a shallow copy, the outer list is copied, but the inner lists remain references to the original. When we change the original[0][0], it also changes in the shallow copy. A deep copy, however, creates a completely separate copy of all elements, so changes in the original do not affect it. Use copy.deepcopy() when you need to ensure changes do not propagate back to the original object.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-31-what-is-the-difference-between-staticmethod-and-classmethod-in-python\" class=\"wp-block-heading\">31. What is the difference between staticmethod and classmethod in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A staticmethod is a method that does not depend on the class instance. It does not use self or cls. A classmethod, on the other hand, takes cls as the first argument and can modify class-level variables.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>class Example:\r\n\r\n\u00a0\u00a0\u00a0\u00a0class_variable = \"I am a class variable\"\r\n\r\n\u00a0\u00a0\u00a0\u00a0@staticmethod\r\n\r\n\u00a0\u00a0\u00a0\u00a0def static_method():\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return \"I do not use class variables.\"\r\n\r\n\u00a0\u00a0\u00a0\u00a0@classmethod\r\n\r\n\u00a0\u00a0\u00a0\u00a0def class_method(cls):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return f\"I can access: {cls.class_variable}\"\r\n\r\n# Calling methods\r\n\r\nprint(Example.static_method())\u00a0 # No class interaction\r\n\r\nprint(Example.class_method()) \u00a0 # Accesses class variables<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: A staticmethod behaves like a regular function inside a class. It does not need any reference to the class itself. A classmethod, however, has access to class variables and can modify them. This is useful when you need a method that operates at the class level rather than the instance level.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-32-how-does-python-s-memory-management-work\" class=\"wp-block-heading\">32. How does Python\u2019s memory management work?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python manages memory using an automatic memory management system. It has a built-in garbage collector that removes unused objects to free memory. Python uses reference counting and garbage collection to manage memory efficiently.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import sys\r\n\r\na = [1, 2, 3]\r\n\r\nb = a\u00a0 # Reference count increases\r\n\r\nprint(sys.getrefcount(a))\u00a0 # Output: 3 (1 for b, 1 for print, 1 internal reference)\r\n\r\ndel b\u00a0 # Reference count decreases\r\n\r\nprint(sys.getrefcount(a))\u00a0 # Output: 2<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: Python tracks how many references an object has. When an object\u2019s reference count drops to zero, Python automatically deletes it. The garbage collector helps clean up cyclic references (objects referencing each other). This system allows Python to handle memory efficiently without requiring manual deallocation.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-33-what-is-the-difference-between-sort-and-sorted-in-python\" class=\"wp-block-heading\">33. What is the difference between sort() and sorted() in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The sort() method sorts a list in place, meaning it modifies the original list and does not return a new one. The sorted() function, on the other hand, returns a new sorted list without changing the original list.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>numbers = [5, 2, 9, 1]\r\n\r\nnumbers.sort()\u00a0 # Sorts in place\r\n\r\nprint(numbers)\u00a0 # Output: [1, 2, 5, 9]\r\n\r\nnumbers = [5, 2, 9, 1]\r\n\r\nsorted_numbers = sorted(numbers)\u00a0 # Returns a new sorted list\r\n\r\nprint(sorted_numbers)\u00a0 # Output: [1, 2, 5, 9]\r\n\r\nprint(numbers)\u00a0 # Original list remains unchanged: [5, 2, 9, 1]<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The sort() is useful when you want to change the list directly. It does not return anything (None). sorted() is useful when you need to keep the original list intact while working with a sorted copy. Both methods support sorting with the key argument, allowing custom sorting logic.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-34-how-does-python-s-map-filter-and-reduce-functions-work\" class=\"wp-block-heading\">34. How does Python\u2019s map(), filter(), and reduce() functions work?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python provides map(), filter(), and reduce() to process data efficiently.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>map(func, iterable) applies a function to each item in an iterable and returns a new iterable.<\/li>\r\n\r\n\r\n\r\n<li>filter(func, iterable) keeps items where func(item) is True.<\/li>\r\n\r\n\r\n\r\n<li>reduce(func, iterable) (from functools) repeatedly applies func() to reduce values to a single result.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example :<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>from functools import reduce\r\n\r\nnumbers = [1, 2, 3, 4, 5]\r\n\r\n# Using map to double each number\r\n\r\ndoubled = list(map(lambda x: x * 2, numbers))\r\n\r\nprint(doubled)\u00a0 # Output: [2, 4, 6, 8, 10]\r\n\r\n# Using filter to get even numbers\r\n\r\nevens = list(filter(lambda x: x % 2 == 0, numbers))\r\n\r\nprint(evens)\u00a0 # Output: [2, 4]\r\n\r\n# Using reduce to find the product of all numbers\r\n\r\nproduct = reduce(lambda x, y: x * y, numbers)\r\n\r\nprint(product)\u00a0 # Output: 120<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: The map() is great for transforming data without using loops and filter() helps extract only relevant elements.\u00a0<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The reduce() processes all elements to compute a single result. It is not a built-in function; you must import it from functools.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-35-explain-the-use-of-python-s-any-and-all-functions-with-examples\" class=\"wp-block-heading\">35. Explain the use of Python\u2019s any() and all() functions with examples.<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Python provides the any() and all() functions to check conditions in an iterable like a list or tuple.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>any(iterable) returns True if at least one element is True. If all elements are False, it returns False.<\/li>\r\n\r\n\r\n\r\n<li>all(iterable) returns True only if all elements are True. If any element is False, it returns False.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">These functions help in filtering and validating data quickly.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>numbers = [0, 1, 2, 3]\u00a0\u00a0\r\n\r\nprint(any(numbers))\u00a0 # True, because 1, 2, and 3 are True\u00a0\u00a0\r\n\r\nprint(all(numbers))\u00a0 # False, because 0 is False\u00a0\u00a0\r\n\r\nvalues = [True, True, True]\u00a0\u00a0\r\n\r\nprint(all(values))\u00a0 # True, all values are True<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: In the first example, any(numbers) returns True because at least one non-zero value exists. However, \u201call(numbers)\u201d returns False because 0 is considered False.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In the second example, \u201call(values)\u201d is True since all elements are True. These functions are useful for checking conditions efficiently in Python programs.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-36-how-can-you-implement-a-singleton-class-in-python\" class=\"wp-block-heading\">36. How can you implement a singleton class in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A singleton class ensures that only one instance of the class exists throughout the program. You can implement it using the __new__ method or a class variable.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>class Singleton:\r\n\r\n\u00a0\u00a0\u00a0\u00a0_instance = None\u00a0 # Class-level variable to store the instance\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __new__(cls):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if cls._instance is None:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cls._instance = super().__new__(cls)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return cls._instance\r\n\r\n# Test Singleton\r\n\r\nobj1 = Singleton()\r\n\r\nobj2 = Singleton()\r\n\r\nprint(obj1 is obj2)\u00a0 # Output: True<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: In the example, _instance is a class variable that stores the single instance of the class. When we create an object, __new__ checks if an instance exists. If not, it creates one; otherwise, it returns the existing one. This ensures that all objects refer to the same instance.<\/p>\r\n\r\n\r\n\r\n<h3 id=\"h-37-how-do-you-reverse-a-linked-list-in-python\" class=\"wp-block-heading\">37. How do you reverse a linked list in Python?<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can reverse a linked list in Python using an iterative or recursive approach. The most common method is using an iterative approach by modifying the next pointers of the nodes.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>class Node:\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __init__(self, data):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.data = data\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.next = None\r\n\r\nclass LinkedList:\r\n\r\n\u00a0\u00a0\u00a0\u00a0def __init__(self):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.head = None\r\n\r\n\u00a0\u00a0\u00a0\u00a0def append(self, data):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new_node = Node(data)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if not self.head:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.head = new_node\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0temp = self.head\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0while temp.next:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0temp = temp.next\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0temp.next = new_node\r\n\r\n\u00a0\u00a0\u00a0\u00a0def reverse(self):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prev = None\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0current = self.head\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0while current:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0next_node = current.next\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0current.next = prev\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prev = current\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0current = next_node\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.head = prev\r\n\r\n\u00a0\u00a0\u00a0\u00a0def print_list(self):\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0temp = self.head\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0while temp:\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(temp.data, end=\" -&gt; \")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0temp = temp.next\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(\"None\")\r\n\r\n# Example Usage\r\n\r\nll = LinkedList()\r\n\r\nll.append(1)\r\n\r\nll.append(2)\r\n\r\nll.append(3)\r\n\r\nll.append(4)\r\n\r\nprint(\"Original List:\")\r\n\r\nll.print_list()\r\n\r\nll.reverse()\r\n\r\nprint(\"Reversed List:\")\r\n\r\nll.print_list()<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Explanation: In this example, we first create a linked list using the Node and LinkedList classes. The reverse() function works by iterating through the list and reversing the next pointers of each node. We use three pointers: prev (to store the previous node), current (to store the current node), and next_node (to store the next node before changing links).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">By updating current.next to prev, we effectively reverse the list. The function continues until all links are reversed, and we update the head to the last node.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Preparing for a Python interview in 2026?\u00a0 Whether you&#8217;re a fresher or an experienced professional, having the right knowledge is key to success.\u00a0 At Codegnan, we help you master Python with hands-on training and real-world projects. With 30,000+ students trained and 1,250+ hiring partners, we know what it takes to land a tech job.\u00a0 In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":39056,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-21343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.3 (Yoast SEO v27.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>37 Python Interview Questions to Crack Any Interview in 2026<\/title>\n<meta name=\"description\" content=\"In this guide, we cover the most important Python interview questions from freshers to advanced levels.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codegnan.com\/python-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"37 Python Interview Questions to Crack Any Interview in 2026\" \/>\n<meta property=\"og:description\" content=\"In this guide, we cover the most important Python interview questions from freshers to advanced levels.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codegnan.com\/python-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Codegnan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codegnan\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-17T15:51:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-26T10:27:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codegnan.com\/wp-content\/uploads\/2025\/02\/Python-Interview-Questions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sairam Uppugundla\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codegnandotcom\" \/>\n<meta name=\"twitter:site\" content=\"@codegnandotcom\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sairam Uppugundla\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/\"},\"author\":{\"name\":\"Sairam Uppugundla\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/person\\\/510a2ce6cfa80a9688733994fe67da52\"},\"headline\":\"37 Python Interview Questions to Crack Any Interview in 2026\",\"datePublished\":\"2025-02-17T15:51:18+00:00\",\"dateModified\":\"2026-05-26T10:27:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/\"},\"wordCount\":4022,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/Python-Interview-Questions.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/\",\"url\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/\",\"name\":\"37 Python Interview Questions to Crack Any Interview in 2026\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/Python-Interview-Questions.jpg\",\"datePublished\":\"2025-02-17T15:51:18+00:00\",\"dateModified\":\"2026-05-26T10:27:39+00:00\",\"description\":\"In this guide, we cover the most important Python interview questions from freshers to advanced levels.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/Python-Interview-Questions.jpg\",\"contentUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/Python-Interview-Questions.jpg\",\"width\":900,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/python-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codegnan.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/codegnan.com\\\/category\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"37 Python Interview Questions to Crack Any Interview in 2026\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#website\",\"url\":\"https:\\\/\\\/codegnan.com\\\/\",\"name\":\"Codegnan\",\"description\":\"Where Talent Meets Opportunity\",\"publisher\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codegnan.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#organization\",\"name\":\"Codegnan\",\"url\":\"https:\\\/\\\/codegnan.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Codegnan-New-Logo.png\",\"contentUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Codegnan-New-Logo.png\",\"width\":420,\"height\":102,\"caption\":\"Codegnan\"},\"image\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codegnan\\\/\",\"https:\\\/\\\/x.com\\\/codegnandotcom\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codegnan\",\"https:\\\/\\\/www.instagram.com\\\/codegnan\\\/\",\"https:\\\/\\\/t.me\\\/codegnan\",\"https:\\\/\\\/www.youtube.com\\\/@Codegnan\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/person\\\/510a2ce6cfa80a9688733994fe67da52\",\"name\":\"Sairam Uppugundla\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g\",\"caption\":\"Sairam Uppugundla\"},\"description\":\"Sairam Uppugunda is the Founder of Codegnan and a technology educator with expertise in Software Development, Python Programming, Data Science, Artificial Intelligence, Full Stack Development, and emerging IT technologies. He has mentored thousands of engineering students and fresh graduates by focusing on practical learning, real-time projects, coding skills, and industry-ready training. Through Codegnan, he actively helps students build successful careers in technology by sharing insights on career guidance, software industry trends, placement preparation, and in-demand skills required for modern tech jobs in Hyderabad, Vijayawada, and other growing IT hubs.\",\"sameAs\":[\"https:\\\/\\\/codegnan.com\"],\"url\":\"https:\\\/\\\/codegnan.com\\\/author\\\/sairam\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"37 Python Interview Questions to Crack Any Interview in 2026","description":"In this guide, we cover the most important Python interview questions from freshers to advanced levels.","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:\/\/codegnan.com\/python-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"37 Python Interview Questions to Crack Any Interview in 2026","og_description":"In this guide, we cover the most important Python interview questions from freshers to advanced levels.","og_url":"https:\/\/codegnan.com\/python-interview-questions\/","og_site_name":"Codegnan","article_publisher":"https:\/\/www.facebook.com\/codegnan\/","article_published_time":"2025-02-17T15:51:18+00:00","article_modified_time":"2026-05-26T10:27:39+00:00","og_image":[{"width":900,"height":400,"url":"https:\/\/codegnan.com\/wp-content\/uploads\/2025\/02\/Python-Interview-Questions.jpg","type":"image\/jpeg"}],"author":"Sairam Uppugundla","twitter_card":"summary_large_image","twitter_creator":"@codegnandotcom","twitter_site":"@codegnandotcom","twitter_misc":{"Written by":"Sairam Uppugundla","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codegnan.com\/python-interview-questions\/#article","isPartOf":{"@id":"https:\/\/codegnan.com\/python-interview-questions\/"},"author":{"name":"Sairam Uppugundla","@id":"https:\/\/codegnan.com\/#\/schema\/person\/510a2ce6cfa80a9688733994fe67da52"},"headline":"37 Python Interview Questions to Crack Any Interview in 2026","datePublished":"2025-02-17T15:51:18+00:00","dateModified":"2026-05-26T10:27:39+00:00","mainEntityOfPage":{"@id":"https:\/\/codegnan.com\/python-interview-questions\/"},"wordCount":4022,"commentCount":0,"publisher":{"@id":"https:\/\/codegnan.com\/#organization"},"image":{"@id":"https:\/\/codegnan.com\/python-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2025\/02\/Python-Interview-Questions.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codegnan.com\/python-interview-questions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codegnan.com\/python-interview-questions\/","url":"https:\/\/codegnan.com\/python-interview-questions\/","name":"37 Python Interview Questions to Crack Any Interview in 2026","isPartOf":{"@id":"https:\/\/codegnan.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codegnan.com\/python-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/codegnan.com\/python-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2025\/02\/Python-Interview-Questions.jpg","datePublished":"2025-02-17T15:51:18+00:00","dateModified":"2026-05-26T10:27:39+00:00","description":"In this guide, we cover the most important Python interview questions from freshers to advanced levels.","breadcrumb":{"@id":"https:\/\/codegnan.com\/python-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codegnan.com\/python-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codegnan.com\/python-interview-questions\/#primaryimage","url":"https:\/\/codegnan.com\/wp-content\/uploads\/2025\/02\/Python-Interview-Questions.jpg","contentUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2025\/02\/Python-Interview-Questions.jpg","width":900,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/codegnan.com\/python-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codegnan.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/codegnan.com\/category\/python\/"},{"@type":"ListItem","position":3,"name":"37 Python Interview Questions to Crack Any Interview in 2026"}]},{"@type":"WebSite","@id":"https:\/\/codegnan.com\/#website","url":"https:\/\/codegnan.com\/","name":"Codegnan","description":"Where Talent Meets Opportunity","publisher":{"@id":"https:\/\/codegnan.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codegnan.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codegnan.com\/#organization","name":"Codegnan","url":"https:\/\/codegnan.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codegnan.com\/#\/schema\/logo\/image\/","url":"https:\/\/codegnan.com\/wp-content\/uploads\/2023\/05\/Codegnan-New-Logo.png","contentUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2023\/05\/Codegnan-New-Logo.png","width":420,"height":102,"caption":"Codegnan"},"image":{"@id":"https:\/\/codegnan.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codegnan\/","https:\/\/x.com\/codegnandotcom","https:\/\/www.linkedin.com\/company\/codegnan","https:\/\/www.instagram.com\/codegnan\/","https:\/\/t.me\/codegnan","https:\/\/www.youtube.com\/@Codegnan"]},{"@type":"Person","@id":"https:\/\/codegnan.com\/#\/schema\/person\/510a2ce6cfa80a9688733994fe67da52","name":"Sairam Uppugundla","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g","caption":"Sairam Uppugundla"},"description":"Sairam Uppugunda is the Founder of Codegnan and a technology educator with expertise in Software Development, Python Programming, Data Science, Artificial Intelligence, Full Stack Development, and emerging IT technologies. He has mentored thousands of engineering students and fresh graduates by focusing on practical learning, real-time projects, coding skills, and industry-ready training. Through Codegnan, he actively helps students build successful careers in technology by sharing insights on career guidance, software industry trends, placement preparation, and in-demand skills required for modern tech jobs in Hyderabad, Vijayawada, and other growing IT hubs.","sameAs":["https:\/\/codegnan.com"],"url":"https:\/\/codegnan.com\/author\/sairam\/"}]}},"_links":{"self":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/posts\/21343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/comments?post=21343"}],"version-history":[{"count":2,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/posts\/21343\/revisions"}],"predecessor-version":[{"id":43105,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/posts\/21343\/revisions\/43105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/media\/39056"}],"wp:attachment":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/media?parent=21343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/categories?post=21343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/tags?post=21343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}