Docsity

Python Programming Ultimate Guide: 8 page Interview and Exam Booster., Study notes of Computer Science

Partial preview of the text

Download Python Programming Ultimate Guide: 8 page Interview and Exam Booster. and more Study notes Computer Science in PDF only on Docsity!

‘@ PYTHON = — Guar == a e 8-PAGE INTERVIEW & #9 EXAM BOOSTER GUIDE High-Yield Question & Answer Bank Special Edition & KEY = a COVERAGE FORMAT Placement Seekers, Basics, Data Structures, Page-by-page clean Engineering Students & OOPs Core, and code snippets with Tech Enthusiasts. Exception Handling. expected outputs. ACE YOUR INTERVIEWS & EXAMS Practice Smart. Code Better. Succeed Faster. Ly, wt INTERVIEW ri EXAM < [> CLEAN CODE a eo? BOOST YOUR FOCUSED rT READY EXAMPLES ‘9 PLACEMENT Author: Siuli Sutradhar y Introduction & Basic Syntax What is Python and why is it interpreted? Ans: Python is a high-level, general-purpose programming language. It is called interpreted because its codee is executed line-by-line by the Python Interpreter, making debugging easier but slightly slower than compiled © languages. What is the difference between Dynamically Typed and Statically Typed languages? must be declared explicitly. Python is Dynamically Typed, meaning the type of a variable is determined at runtime based on the value assigned. Write a Python code snippet to swap two numbers without using a third variable. 5S Ans: In Statically Typed languages (like Java/C++), variable types 2 a, =b, print(f"a: {a} Strings & Slicing Operations How does String Slicing work in Python? Explain with syntax. » @ Ans: Syntaxis string[start:stop:step] _. It extracts a part of a string. What is the difference between find() and index() methods? 2 @ Ans: Both search for a substring. If not found, find() returns -1 ,while index() raises a ValueError . Write a code to reverse a string and check if it is a palindrome. Ans: an ~— Vv python text = reversed_text = text[::-1] is_palindrome = text == reversed_text print(is_palindrome) & Wl Control Flow & Loops What is the purpose of the else clause ina Python for loop? Ans: The else block executes only when the loop eee completes naturally without hitting a break statement. Difference between break, continue , and pass. Ans: break terminates the loop. continue skips the current iteration. pass isa null statement used as a placeholder. Write a loop to print the Fibonacci series up to 5 terms. Ans: _ in range(5): print(a, end="_") aj, b= bi, tab # Output: O01 123 $08 v» 8B as Dictionaries & Sets How do Dictionaries and Sets store data internally? Ans: Both use Hashing for internal storage, allowing O(1) average time complexity for lookups. Sets store unique elements, Dictionaries store key-value pairs. What happens if you access a non-existent key in a dictionary? How to prevent it? Ans: It raises a KeyError. To prevent this, use the .get(key, default) method instead of brackets. Write code to merge two dictionaries. Ans: python dict = {4a “bes 2} dict2 = {'b': 3, : 4} merged = {**dict1, **dict2} print (merged) Functions & Lambda Expressions What are *args and **kwargs in Python functions? a Ans: *args allows passing a variable number of Al non-keyword (positional) arguments as a Tuple. **kwargs allows passing keyworded arguments as a Dictionary. What is a Lambda function? -C- Ans: An anonymous, single-line function defined using the lambda keyword without a name. ©® Write a lambda function to multiply two numbers. Ans: python 1 multiply = lambda x, y: x * y 3. print(multiply(4, 5)) # Output: 20