502 Python Interview Questions to Crack Placements in 2027
You commented python, so here are all 502, free, with a link for each: 338 interview questions with written answers, 100 coding exercises with solutions, and 64 tricky "what's the output?" snippets. They come from three GitHub repos, and every link jumps straight to its answer. I removed the questions one repo repeats, so the count is unique questions.
The short version: Python rounds test three things: how well you know the language (Part 1), whether you can write it (Part 2), and whether you understand what it actually does (Part 3). Start with the 4 topics below, then build the 3 small things after.
The three repos
learning-zone/python-basics ~1.6K ★
github.com/learning-zone/python-basics
338 Python interview questions with answers and code, in 22 topics from data types to concurrency.
zhiwehu/Python-programming-exercises ~29.7K ★
github.com/zhiwehu/Python-programming-exercises
100 programming exercises, each with hints and a full solution. The first ones are labelled beginner to advanced.
satwikkansal/wtfpython ~37.1K ★
github.com/satwikkansal/wtfpython
64 surprising Python snippets with explanations of why they behave the way they do. Interviewers love these.
The 4 I'd start with
- Data types and mutability. Data types, core data structures and mutable vs immutable. Start with is a tuple mutable or immutable?
- Functions, *args and **kwargs. Functions, lambdas and *args and **kwargs.
- Iterators, generators and decorators. Iterators and generators, decorators and context managers. This is where Python rounds separate juniors from seniors.
- The "what's the output?" snippets. All 64 in Part 3. Read the snippet, guess the output, then read why.
What to build to prove you get it
- A decorator that times any function and logs slow calls.
- A generator that reads a huge log file line by line without loading it into memory.
- A context manager that opens a database connection and always closes it.
You don't need all 502. You need to explain generators and decorators while writing one live.
Jump to a topic
Introduction (30) · Data Types (34) · Dictionary (8) · Operators (10) · Control Flow Statements (20) · Core Data Structures (27) · Functions (24) · Lambda Functions (8) · Modules and Packages (14) · Object-Oriented Programming (28) · Exception Handling (12) · File Handling (12) · Memory Management (6) · Garbage Collector (3) · Mutable vs Immutable (5) · Iterators and Generators (13) · Decorators (2) · Context Managers (2) · Concurrency and Parallelism (7) · Testing and Debugging (7) · Miscellaneous (61) · Numerical Computing (5) · Coding exercises (100) · What's the output? (64)
Part 1: Python interview questions with answers (338)
Source: github.com/learning-zone/python-basics
Introduction (30)
- What is Python?
- What can Python do?
- When is using Python the "right choice" for a project?
- What are some drawbacks of the Python language?
- We know Python is all the rage these days. But to be truly accepting of a great technology, you must know its pitfalls as well?
- What are the key differences between Python 2 and 3?
- What are some key differences to bear in mind when coding in Python vs. Java?
- What are the key features of Python?
- How is a .pyc file different from a .py file?
- How does the Python version numbering scheme work?
- What Are The Implementation In Python Program?
- What Are Applications of Python?
- Mention five benefits of using Python?
- Is Python interpreted or compiled?
- What are some alternative implementations to CPython? When and why might you use them?
- Is Python a compiled language?
- Why Python instead of Scala on Spark when Scala has better performance?
- Describe some features of Python.
- How does Python execute code?
- What is the difference between Python 2.7+ and Python 3?
- Is Python compiled? If yes, how? If not, how?
- What does dynamically / duck typed mean?
- When would I not use Python?
- What is DRY, and how can I apply it through OOP or FP?
- When would I use Python?
- Give examples of Python frameworks.
- How is Python interpreted?
- What is Dynamic Typing?
- Justify this statement: Everything is an object in Python.
- What is the difference between Python and Java?
Data Types (34)
- How do I convert a number to a string?
- Does Python support strongly for regular expressions?
- How do you perform pattern matching in Python? Explain.
- Write a regular expression that will accept an email id. Use the re module.
- Explain split(), sub(), subn() methods of re module in Python.
- Which of the following is an invalid statement?
- What is the output of the following?
- What is the output of the following? (2)
- What is the output of the following? (3)
- Write a Python function that checks whether a passed string is palindrome Or not?
- Explain join() and split() in Python?
- Is Python case-sensitive?
- How do you remove the leading whitespace in a string?
- What data types does Python support?
- What is a docstring?
- What is slicing?
- What is a namedtuple?
- How would you declare a comment in Python?
- How would you convert a string into an int in Python?
- How do you take input in Python?
- What is a frozen set in Python?
- How will you capitalize the first letter of a string?
- How will you check if all characters in a string are alphanumeric?
- What is the concatenation?
- How will you find, in a string, the first word that rhymes with 'cake'?
- How do you calculate the length of a string?
- What does the following code output?
- What are The Data Types Supports in Python Language?
- In Python what is slicing?
- How you can convert a number to a string?
- What are some built-in types in Python?
- What are bindings — what does it mean for a value to be bound to a variable?
- What is a Unicode string?
- Explain indexing and slicing.
Dictionary (8)
- How is the Implementation of Python's dictionaries done?
- What is a dictionary in Python?
- How do you get a list of all the keys in a dictionary?
- What is the Dictionary?
- How do you create a dictionary?
- Explain dict.
- How do you create a dictionary that preserves the order of pairs?
- Can you use a mutable data structure as a key in a dictionary?
Operators (10)
- Explain the //, %, and ** operators in Python.
- How many kinds of operators do we have in Python? Explain arithmetic operators.
- Explain relational operators in Python?
- What are assignment operators in Python?
- Explain logical operators in Python.
- What are membership, operators?
- Explain identity operators in Python.
- Finally, tell us about bitwise operators in Python.
- How would you work with numbers other than those in the decimal number system?
- Mention the use of // operator in Python?
Control Flow Statements (20)
- What is the built-in function used in Python to iterate over a sequence of numbers?
- What is the statement that can be used in Python if a statement is required syntactically but the program requires no action?
- Explain the ternary operator in Python?
- What is the pass statement in Python?
- If you are ever stuck in an infinite loop, how will you break out of it?
- How many arguments can the range() function take?
- Explain Control flow statements.
- What are the two major loop statements?
- Under what circumstances would one use a while statement rather than for?
- What happens if output an else statement after after block?
- Explain the use of break and continue in Python looping.
- When would you use a continue statement in a for loop?
- When would you use a break statement in a for loop?
- What is the structure of a for loop?
- What is the structure of a while loop?
- Use a for loop and illustrate how you would define and print the characters in a string out, one per line.
- Given the string "I LoveQPython" use afor loop and illustrate printing each character tip to, but not including the Q.
- Given the string "I Love Python" print out each character except for the spaces, using a for loop.
- for loop is implemented in python language as follows:
- What is pass in Python?
Core Data Structures (27)
- Is it possible to assign multiple var to values in list?
- Write a sorting algorithm for a numerical dataset in Python?
- How will you remove last object from a list?
- What are negative indexes and why are they used?
- How many kinds of sequences are supported by Python? What are they?
- Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
- Differentiate between append() and extend() methods.?
- Which of the following is not the correct syntax for creating a set?
- Write a Python program to calculate the sum of a list of numbers?
- How would you randomize the contents of a list in-place?
- What is tuple unpacking?
- What is a Tuple?
- What is List Comprehensions feature of Python used for?
- What are lambda expressions, list comprehensions and generator expressions?
- What will be printed out by the second append() statement below?
- What will be printed out by the last statement below?
- How do you reverse a list?
- How would you merge two sorted lists?
- Tell me some data structures in Python?
- What is List Comprehension? Show with example.
- How do you create a list?
- What is a list comprehension? Why would you use one?
- What is list/dict comprehension?
- How to make an array in Python?
- When to use list / tuple / set / dict?
- When to use list comprehensions and when to avoid them?
- What is the difference between a tuple and a list? Where will you use each?
Functions (24)
- What are *args, **kwargs ?
- How can I pass optional or keyword parameters from one function to another?
- What are higher ordered functions?
- Explain help() and dir() functions in Python?
- What is a closure in Python?
- Why are identifier names with a leading underscore disparaged?
- How can you declare multiple assignments in one statement?
- What is a function?
- What is recursion?
- What does the function zip() do?
- What is a Counter in Python?
- Explain the use of the 'nonlocal' keyword in Python.
- What is the global keyword?
- Mention what are the rules for local and global variables in Python?
- How can you share global variables across modules?
- How can you return multiple values from a function?
- What is the fastest way to swap the values bound to two variables?
- Do functions return something even if there is not a return statement?
- How to pass optional or keyword arguments.
- What is the use of enumerate() in Python?
- Namespace vs scope?
- How do you create a Python function?
- How does a function return values?
- What happens when a function does not have a return statement?
Lambda Functions (8)
- What is lambda? What are Lambda Functions ?
- What is map function in Python?
- Name few methods that are used to implement Functionally Oriented Programming in Python?
- Explain a few methods to implement Functionally Oriented Programming in Python.
- Explain the difference between map(), reduce(), and filter()?
- How can you implement functional programming and why would you?
- Explain map(), filter(), reduce(), and lambda.
- What are map(), filter(), and reduce() functions?
Modules and Packages (14)
- How do I find the current module name?
- How do I access a module written in Python from C?
- How do you create your own package in Python?
- What is the purpose of PYTHONSTARTUP, PYTHONCASEOK, PYTHONHOME & PYTHONPATH environment variables?
- What is a Python module?
- Name the File-related modules in Python?
- What is the PYTHONPATH variable?
- Where is math.py (socket.py, regex.py, etc.) source file?
- How to Search Path of Modules?
- What are the Packages?
- OS Module
- What is module and package in Python?
- Should I import an entire module?
- How are modules used in a Python program?
Object-Oriented Programming (28)
- How do I call a method defined in a base class from a derived class that overrides it?
- How can I organize my code to make it easier to change the base class?
- Explain Inheritance in Python with an example?
- What is Hierarchical Inheritance?
- Suppose class C inherits from classes A and B as class C(A,B).Classes A and B both have their own versions of method func(). If we call func() from an object of class C, which version gets invoked?
- Which methods/functions do we use to determine the type of instance and inheritance?
- Is Python object oriented? what is object oriented programming?
- Does Python supports interfaces like in Java? Discuss?
- What are Accessors, mutators, @property?
- What are accessors, mutators, and @property?
- What do you mean by overriding methods?
- What is the Difference Between Methods & Constructors?
- What is the Encapsulation?
- How are instance variables different from class variables?
- What is Method Resolution Order (MRO)?
- What is multiple inheritance and when should you use it?
- What is a metaclass?
- What are properties and what is the point?
- What is polymorphism, and when would I use it?
- What is a class and what is self?
- Explain isinstance()
- What are static methods, class methods, and instance methods?
- Difference between new-style and old-style classes.
- What are Metaclasses?
- What is a descriptor?
- What is MRO (Method Resolution Order)?
- How is a Python class created?
- How is a Python class instantiated?
Exception Handling (12)
- Explain the use of try: except: raise, and finally:
- Illustrate the proper use of Python error handling.
- What are the Runtime Errors?
- What is Abnormal Termination?
- What is try Block?
- What happens if you have an error in an __init__ statement?
- What happens in Python if you try to divide by zero?
- How to handle exceptions?
- What are the different types of exceptions in Python?
- How to write your own custom exception handling?
- Why does exception handling have a finally block?
- What happens if an error occurs that is not handled in the except block?
File Handling (12)
- How do I copy a file? How to copy object in Python? Diff between shallow copy and deep copy?
- Write a one-liner that will count the number of capital letters in a file. Your code should work even if the file is too big to fit in memory?
- How to display the contents of text file in reverse order?How will you reverse a list?
- Write a Python program to read a random line from a file.
- Write a Python program to count the number of lines in a text file?
- Write Python logic to count the number of capital letters in a file?
- What functions or methods will you use to delete a file in Python?
- What is File Handling?
- Explain how to delete a file in Python?
- How would you count the lines in a file?
- How to access a file on a Linux server using Python?
- Explain all the file processing modes supported by Python.
Memory Management (6)
- How is memory managed in Python?
- How will you check memory leak on Linux?
- What is the importance of reference counting?
- What is the size of an integer in Python?
- How does Python manage memory?
- How will you measure memory on a Linux server?
Garbage Collector (3)
- What is Garbage Collection?
- Why isn't all memory freed when Python exits?
- Whenever you exit Python, is all memory de-allocated?
Mutable vs Immutable (5)
- What Are The Types of Objects Support in Python Language?
- Python is Call by Value or Call by Reference? How are arguments passed by value or by reference?
- Explain parameter-passing mechanism in python?
- How can you copy an object in Python?
- Is a tuple mutable or immutable?
Iterators and Generators (13)
- In Python what are iterators?
- What are generators in Python?
- So, what is an iterator, then?
- Explain generators and iterators in python?
- What is a generator? What can it be used for?
- What are Generators?
- What are Iterators?
- Can a generator be used to create iterators? Give an example.
- Can iterators be used to create generators?
- What are iterators and generators?
- What does the yield statement do?
- What is a generator? Why would I use one?
- What is yield?
Decorators (2)
Context Managers (2)
Concurrency and Parallelism (7)
- What is multithreading?
- Why do not my signal handlers work?
- Why is that none of my threads are not running? How can I make it work?
- What is Threads Life Cycle?
- What is scheduling?
- Does Python provide thread-safe multi-threading?
- What do you mean by non-blocking I/O?
Testing and Debugging (7)
- How do you debug a program in Python? Answer in brief.
- List some pdb commands.
- What command do we use to debug a Python program?
- What are the tools that help to find bugs or perform static analysis?
- What is unittest in Python? What's your approach to unit testing in Python?
- How would you perform unit-testing on your Python code?
- How do I test a Python program or component?
Miscellaneous (61)
- What will be the output of the code below?
- What is a method?
- What is __slots__ and when is it useful?
- What is Monkey patching ? Give example ?
- Explain serialization and deserialization / Pickling and unpicking?
- How to open a file c:\scores.txt for writing?
- What is TkInter?
- How to retrieve data from a table in MySQL database through Python code?
- How would you generate a random number in Python?
- With Python, how do you find out which directory you are currently in?
- How would you make a Python script executable on Unix?
- Differentiate between the append() and extend() methods of a list.
- What is JSON? Describe in brief how you'd convert JSON data into Python data?
- How do you execute a Python Script?
- What is a namespace in Python?
- Explain the differences between local and global namespaces.
- Name the four main types of namespaces in Python?
- When would you use triple quotes as a delimiter?
- How to use GUI that comes with Python to test your code?
- How do I make a Python script executable on UNIX?
- How do I find undefined g++ symbols __builtin_new or __pure_virtual?
- How do I send mail from a Python script?
- How can I mimic CGI form submission (METHOD=POST)? I would like to retrieve web pages that are the result of posting a form.
- Executing DML Commands Through Python Programs?
- How Python is interpreted?
- Explain how can you make a Python Script executable on Unix?
- Explain how can you generate random numbers in Python?
- Mention the use of the split function in Python?
- Mention what is the difference between Django, Pyramid, and Flask?
- Explain how you can minimize the Memcached server outages in your Python Development?
- Explain what is Dogpile effect? How can you prevent this effect?
- Explain how Memcached should not be used in your Python project?
- What is Flask & its benefits?
- Mention what is Flask-WTF and what are their features?
- Explain what is the common way for the Flask script to work?
- Explain how you can access sessions in Flask?
- Is Flask an MVC model and if yes give an example showing MVC pattern for your application?
- Explain database connection in Python Flask?
- What are the standard Python libraries commonly used?
- What are serialization formats in Python?
- What version of Azure Data Factory are you using?
- How to execute Java code from Python?
- How to find PID of a process and how much resources it is taking on Linux?
- What are tools for data ingestion?
- What is inheritance?
- Differentiate between append() and extend() methods of a list.
- Explain ctypes and why you would use them?
- How do you go about packaging Python code?
- What does __some_variable__ (dunder / magic attribute) mean?
- What is the difference between str() and repr()?
- What are Middlewares?
- How to generate random numbers?
- What is virtualenv?
- What is a context processor?
- What are exec() and eval()?
- How to pass command-line arguments?
- What are ord() and chr()?
- Difference between input() and raw_input()?
- Why do we write if __name__ == "__main__" in a Python script?
- What is PEP 8?
- What parameters should you check when a server is down?
Numerical Computing (5)
- How to get indices of N maximum values in a NumPy array?
- What is the difference between NumPy and SciPy?
- Name few Python modules for Statistical, Numerical and scientific computations ?
- What is NumPy? Is it better than a list?
- How would you create an empty NumPy array?
Part 2: Coding exercises with solutions (100)
Source: github.com/zhiwehu/Python-programming-exercises
Exercises 1 to 25 (25)
- Exercise 1: Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,...
- Exercise 2: Write a program which can compute the factorial of a given numbers.
- Exercise 3: With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that...
- Exercise 4: Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a...
- Exercise 5: Define a class which has at least two methods:
- Exercise 6: Write a program that calculates and prints the value according to the given formula:
- Exercise 7: Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value...
- Exercise 8: Write a program that accepts a comma separated sequence of words as input and prints the words in a...
- Exercise 9: Question£º
- Exercise 10: Write a program that accepts a sequence of whitespace separated words as input and prints the words after...
- Exercise 11: Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then...
- Exercise 12: Write a program, which will find all such numbers between 1000 and 3000 (both included) such that each...
- Exercise 13: Write a program that accepts a sentence and calculate the number of letters and digits.
- Exercise 14: Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.
- Exercise 15: Write a program that computes the value of a+aa+aaa+aaaa with a given digit as the value of a.
- Exercise 16: Use a list comprehension to square each odd number in a list. The list is input by a sequence of...
- Exercise 17: Write a program that computes the net amount of a bank account based a transaction log from console input....
- Exercise 18: A website requires the users to input username and password to register. Write a program to check the...
- Exercise 19: You are required to write a program to sort the (name, age, height) tuples by ascending order where name...
- Exercise 20: Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given...
- Exercise 21: Question
- Exercise 22: Write a program to compute the frequency of the words from the input. The output should output after...
- Exercise 23: Write a method which can calculate square value of number
- Exercise 24:
- Exercise 25: Define a class, which have a class parameter and have a same instance parameter.
Exercises 26 to 50 (25)
- Exercise 26: Define a function which can compute the sum of two numbers.
- Exercise 27: Define a function that can convert a integer into a string and print it in console.
- Exercise 28: Define a function that can convert a integer into a string and print it in console.
- Exercise 29: Define a function that can receive two integral numbers in string form and compute their sum and then...
- Exercise 30: Define a function that can accept two strings as input and concatenate them and then print it in console.
- Exercise 31: Define a function that can accept two strings as input and print the string with maximum length in...
- Exercise 32: Define a function that can accept an integer number as input and print the "It is an even number" if the...
- Exercise 33: Define a function which can print a dictionary where the keys are numbers between 1 and 3 (both included)...
- Exercise 34: Define a function which can print a dictionary where the keys are numbers between 1 and 20 (both included)...
- Exercise 35: Define a function which can generate a dictionary where the keys are numbers between 1 and 20 (both...
- Exercise 36: Define a function which can generate a dictionary where the keys are numbers between 1 and 20 (both...
- Exercise 37: Define a function which can generate and print a list where the values are square of numbers between 1 and...
- Exercise 38: Define a function which can generate a list where the values are square of numbers between 1 and 20 (both...
- Exercise 39: Define a function which can generate a list where the values are square of numbers between 1 and 20 (both...
- Exercise 40: Define a function which can generate a list where the values are square of numbers between 1 and 20 (both...
- Exercise 41: Define a function which can generate and print a tuple where the value are square of numbers between 1 and...
- Exercise 42: With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one line and...
- Exercise 43: Write a program to generate and print another tuple whose values are even numbers in the given tuple...
- Exercise 44: Write a program which accepts a string as input to print "Yes" if the string is "yes" or "YES" or "Yes",...
- Exercise 45: Write a program which can filter even numbers in a list by using filter function. The list is:...
- Exercise 46: Write a program which can map() to make a list whose elements are square of elements in...
- Exercise 47: Write a program which can map() and filter() to make a list whose elements are square of even number in...
- Exercise 48: Write a program which can filter() to make a list whose elements are even number between 1 and 20 (both...
- Exercise 49: Write a program which can map() to make a list whose elements are square of numbers between 1 and 20 (both...
- Exercise 50: Define a class named American which has a static method called printNationality.
Exercises 51 to 75 (25)
- Exercise 51: Define a class named American and its subclass NewYorker.
- Exercise 52: Define a class named Circle which can be constructed by a radius. The Circle class has a method which can...
- Exercise 53: Define a class named Rectangle which can be constructed by a length and width. The Rectangle class has a...
- Exercise 54: Define a class named Shape and its subclass Square. The Square class has an init function which takes a...
- Exercise 55: Please raise a RuntimeError exception.
- Exercise 56: Write a function to compute 5/0 and use try/except to catch the exceptions.
- Exercise 57: Define a custom exception class which takes a string message as attribute.
- Exercise 58: Assuming that we have some email addresses in the "username@companyname.com" format, please write program...
- Exercise 59: Assuming that we have some email addresses in the "username@companyname.com" format, please write program...
- Exercise 60: Write a program which accepts a sequence of words separated by whitespace as input to print the words...
- Exercise 61: Print a unicode string "hello world".
- Exercise 62: Write a program to read an ASCII string and to convert it to a unicode string encoded by utf-8.
- Exercise 63: Write a special comment to indicate a Python source code file is in unicode.
- Exercise 64: Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0).
- Exercise 65: Write a program to compute:
- Exercise 66: The Fibonacci Sequence is computed based on the following formula:
- Exercise 67: The Fibonacci Sequence is computed based on the following formula:
- Exercise 68: Please write a program using generator to print the even numbers between 0 and n in comma separated form...
- Exercise 69: Please write a program using generator to print the numbers which can be divisible by 5 and 7 between 0...
- Exercise 70: Please write assert statements to verify that every number in the list [2,4,6,8] is even.
- Exercise 71: Please write a program which accepts basic mathematic expression from console and print the evaluation result.
- Exercise 72: Please write a binary search function which searches an item in a sorted list. The function should return...
- Exercise 73: Please write a binary search function which searches an item in a sorted list. The function should return...
- Exercise 74: Please generate a random float where the value is between 10 and 100 using Python math module.
- Exercise 75: Please generate a random float where the value is between 5 and 95 using Python math module.
Exercises 76 to 100 (25)
- Exercise 76: Please write a program to output a random even number between 0 and 10 inclusive using random module and...
- Exercise 77: Please write a program to output a random number, which is divisible by 5 and 7, between 0 and 10...
- Exercise 78: Please write a program to generate a list with 5 random numbers between 100 and 200 inclusive.
- Exercise 79: Please write a program to randomly generate a list with 5 even numbers between 100 and 200 inclusive.
- Exercise 80: Please write a program to randomly generate a list with 5 numbers, which are divisible by 5 and 7 ,...
- Exercise 81: Please write a program to randomly print a integer number between 7 and 15 inclusive.
- Exercise 82: Please write a program to compress and decompress the string "hello world!hello world!hello world!hello...
- Exercise 83: Please write a program to print the running time of execution of "1+1" for 100 times.
- Exercise 84: Please write a program to shuffle and print the list [3,6,7,8].
- Exercise 85: Please write a program to shuffle and print the list [3,6,7,8].
- Exercise 86: Please write a program to generate all sentences where subject is in ["I", "You"] and verb is in ["Play",...
- Exercise 87: Please write a program to print the list after removing delete even numbers in [5,6,77,45,22,12,24].
- Exercise 88: By using list comprehension, please write a program to print the list after removing delete numbers which...
- Exercise 89: By using list comprehension, please write a program to print the list after removing the 0th, 2nd, 4th,6th...
- Exercise 90: By using list comprehension, please write a program generate a 3*5*8 3D array whose each element is 0.
- Exercise 91: By using list comprehension, please write a program to print the list after removing the 0th,4th,5th...
- Exercise 92: By using list comprehension, please write a program to print the list after removing the value 24 in...
- Exercise 93: With two given lists [1,3,6,78,35,55] and [12,24,35,24,88,120,155], write a program to make a list whose...
- Exercise 94: With a given list [12,24,35,24,88,120,155,88,120,155], write a program to print this list after removing...
- Exercise 95: Define a class Person and its two child classes: Male and Female. All classes have a method "getGender"...
- Exercise 96: Please write a program which count and print the numbers of each character in a string input by console.
- Exercise 97: Please write a program which accepts a string from console and print it in reverse order.
- Exercise 98: Please write a program which accepts a string from console and print the characters that have even indexes.
- Exercise 99: Please write a program which prints all permutations of [1,2,3]
- Exercise 100: Write a program to solve a classic ancient Chinese puzzle:
Part 3: Tricky "what's the output?" snippets (64)
Source: github.com/satwikkansal/wtfpython
Strain your brain! (31)
- First things first!
- Strings can be tricky sometimes
- Be careful with chained operations
- How not to use is operator
- Hash brownies
- Deep down, we're all the same.
- Disorder within order
- Keep trying...
- For what?
- Evaluation time discrepancy
- is not ... is not is (not ...)
- A tic-tac-toe where X wins in the first attempt!
- Schrödinger's variable
- The chicken-egg problem
- Subclass relationships
- Methods equality and identity
- All-true-ation
- The surprising comma
- Strings and the backslashes
- not knot!
- Half triple-quoted strings
- What's wrong with booleans?
- Class attributes and instance attributes
- yielding None
- Yielding from... return!
- Nan-reflexivity
- Mutating the immutable!
- The disappearing variable from outer scope
- The mysterious key type conversion
- Let's see if you can guess this?
- Exceeds the limit for integer string conversion
Slippery Slopes (16)
- Modifying a dictionary while iterating over it
- Stubborn del operation
- The out of scope variable
- Deleting a list item while iterating
- Lossy zip of iterators
- Loop variables leaking out!
- Beware of default mutable arguments!
- Catching the Exceptions
- Same operands, different story!
- Name resolution ignoring class scope
- Rounding like a banker
- Needles in a Haystack
- Splitsies
- Wild imports
- All sorted?
- Midnight time doesn't exist?
The Hidden treasures! (9)
- Okay Python, Can you make me fly?
- goto, but why?
- Brace yourself!
- Let's meet Friendly Language Uncle For Life
- Even Python understands that love is complicated
- Yes, it exists!
- Ellipsis
- Inpinity
- Let's mangle
Appearances are deceptive! (3)
Miscellaneous (5)
- += is faster
- Let's make a giant string!
- Slowing down dict lookups
- Bloating instance dicts
- Minor Ones
How I'd use this
- Answer each question out loud before you open the answer. Interviews test explaining, not recognising.
- Do the coding exercises without looking at the hints first. Time yourself: 15 minutes each.
- For every output snippet you get wrong, write one line on why. That's your revision sheet for the night before.
- Build the 3 things above and push them to GitHub. "I wrote my own context manager" beats "I know Python" on a resume.
Doing JavaScript too? Read 518 JavaScript interview questions.
Follow @avi_vashishta29 for one practical AI dev resource a day.