Post content
Top 10 Python Interview Questions with Solutions✅ 1️⃣What is the difference between a list and a tuple? ⦁ List: mutable, defined with [] ⦁ Tuple: immutable, defined with () lst = [1, 2, 3] tpl = (1, 2, 3) 2️⃣How to reverse a string in Python? s = "Hello" rev = s[::-1] # 'olleH' 3️⃣Write a function to find factorial using recursion. def factorial(n): return 1 if n == 0 else n * factorial(n-1) 4️⃣How do you handle exceptions? ⦁ Use try and except blocks. try: x = 1 / 0 except ZeroDivisionError: print("Cannot divide by zero") 5️⃣Difference between == and is? ⦁ == compares values ⦁ is compares identities (memory locations) 6️⃣How to check if a number is prime? def is_prime(n): if n < 2: return False for i in range(2,int(n**0.5)+1): if n % i == 0: return False return True 7️⃣What are list comprehensions? Give example. ⦁ Compact way to create lists squares = [x*x for x in range(5)] 8️⃣How to merge two dictionaries? ⦁ Python 3.9+ d1 = {'a':1} d2 = {'b':2} merged = d1 | d2 9️⃣Explain *args and **kwargs. ⦁ *args: variable number of positional arguments ⦁ **kwargs: variable number of keyword arguments 10️⃣How do you read a file in Python? with open('file.txt', 'r') as f: data = f.read() Python Interview Resources: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L Tap ❤️ for more