Python Interview Preparation Questions
Introduction & Python Basics
• What is the Python interactive shell (REPL) and how is it used?
• Differentiate between integers, floating-point numbers, and strings in Python.
• How does Python handle integer division (//) and floating-point division (/)?
• Explain string concatenation and replication with examples.
• How do you store values in variables? What are Python’s naming rules for variables?
• What does it mean that Python is dynamically typed?
• What is the difference between single, double, and triple quotes in strings?
• What does 'dissecting your program' mean in debugging?
• Explain type conversion functions like int(), float(), and str().
• What does immutability mean with respect to strings?
Flow Control
• What are Boolean values in Python?
• List all comparison operators in Python with examples.
• Differentiate between Boolean operators (and, or, not) and bitwise operators (&, |, ~).
• Can you mix Boolean and comparison operators in a single expression? Give an example.
• Explain Python’s order of precedence when evaluating logical and comparison operators together.
• Explain the role of if, elif, and else statements.
• What is the difference between a while loop and a for loop?
• How do break and continue statements work in loops?
• How can you import modules in Python? Give an example.
• What is the purpose of [Link]()? How does it differ from return?
• Why is indentation important in Python’s flow control statements?
Functions
• How do you define a function in Python?
• What is the difference between parameters and arguments?
• Explain return values and the purpose of the return statement.
• What does it mean if a function returns None?
• What are keyword arguments? Show an example with print().
• Explain local vs global scope in Python.
• What does the global statement do?
• How does exception handling work with try, except, finally?
• Differentiate between raise and catching exceptions with except.
Lists
• What is the list data type in Python?
• How do you access elements of a list using indexing and slicing?
• How do augmented assignment operators (+=, *=) work with lists?
• Explain list mutability with an example.
• Name at least five list methods and their use.
• How do you add and remove elements from a list?
• How can you sort and reverse a list?
Dictionaries & Structuring Data
• What is the dictionary data type? How is it different from a list?
• How do you add, update, and delete key-value pairs in a dictionary?
• What happens if you access a dictionary key that doesn’t exist?
• How can you iterate through keys, values, and items in a dictionary?
• What is pretty printing, and how does the pprint module help?
• Give an example of using a dictionary to model real-world data.
• When would you use a dictionary instead of a list?
Manipulating Strings
• How do you access characters and substrings in a string?
• Are strings mutable or immutable in Python? Explain with an example.
• List at least five useful string methods with examples.
• How do split() and join() work?
• How do you strip whitespace from the beginning and end of a string?
• How does string replacement with replace() work?
Reading & Writing Files
• What is the difference between absolute and relative file paths?
• Which [Link] functions are most useful when working with files?
• Explain file modes: r, w, a, rb, wb.
• Why is with open(...) preferred for file handling?
• How do you read the entire contents of a file vs line by line?
• What is the purpose of the shelve module?
• How do you save Python variables in a text file using [Link]()?
Organizing Files
• What operations can you perform with the shutil module?
• How do you copy and move files with shutil?
• What does [Link]() return when walking a directory tree?
• How do you delete a file vs a folder in Python?
• How do you create and extract a ZIP file using the zipfile module?
• Why might you compress files programmatically?
Web Scraping
• What is the purpose of the webbrowser module in Python?
• How does the [Link] project work?
• How do you download files using the requests module?
• What’s the difference between [Link] and [Link] in requests?
• How do you save a downloaded binary file like an image or PDF?
• What are common HTTP status codes you might encounter in requests?
• What is HTML, and why is it important for web scraping?
• How would you extract data from or tags on a webpage?
• Why is the BeautifulSoup library often used with web scraping?
• What are some ethical or legal considerations in web scraping?
• Suppose you want to back up all .txt files in a folder into a ZIP archive. How would you approach this?
• You need to save a dictionary of student records permanently. Which modules would you use?
• You are asked to create a script that opens Google Maps at your clipboard address. Which modules
are required?
• How would you write a script to crawl through a directory and list all image files (.jpg, .png)?
• You downloaded a CSV file using requests. How will you save it and later read its contents into
Python?