Python Interview Questions Freshers
Python Interview Questions Freshers
a = 5
b = 10
a, b = b, a
print(a, b) # Output: 10 5
def is_prime(n):
if n <= 1:
return False
if n % i == 0:
return False
return True
print(is_prime(7)) # True
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
fibonacci(5) # Output: 0 1 1 2 3
def is_palindrome(s):
return s == s[::-1]
print(is_palindrome('madam')) # True
5. Find second largest element in a list
def second_largest(nums):
second = first
first = num
second = num
return second
s = 'hello world'
text = f.read()
words = text.split()
print(len(words))
class Animal:
def speak(self):
return 'Sound'
class Dog(Animal):
def speak(self):
return 'Bark'
d = Dog()
try:
a = 5 / 0
except ZeroDivisionError: