0% found this document useful (0 votes)
3 views1 page

Python Interview Questions & Answers

The document contains Python coding interview questions along with their answers. It includes functions for reversing a string, checking for palindromes, finding duplicate elements in a list, counting vowels, calculating factorial using recursion, and finding the largest element in a list. Each function is accompanied by example usage and expected output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Python Interview Questions & Answers

The document contains Python coding interview questions along with their answers. It includes functions for reversing a string, checking for palindromes, finding duplicate elements in a list, counting vowels, calculating factorial using recursion, and finding the largest element in a list. Each function is accompanied by example usage and expected output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Coding Interview Questions with Answers ■■

1■■ Reverse a String

def reverse_string(s):
return s[::-1]

print(reverse_string("hello")) # Output: "olleh"

2■■ Check Palindrome

def is_palindrome(s):
s = [Link](" ", "").lower()
return s == s[::-1]

print(is_palindrome("Race car")) # Output: True

3■■ Find Duplicate Elements in List

from collections import Counter

def find_duplicates(lst):
count = Counter(lst)
return [item for item, freq in [Link]() if freq > 1]

print(find_duplicates([1, 2, 3, 2, 4, 1])) # Output: [1, 2]

4■■ Count Vowels in a String

def count_vowels(s):
return sum(1 for char in [Link]() if char in "aeiou")

print(count_vowels("Python is fun")) # Output: 4

5■■ Find Factorial Using Recursion

def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)

print(factorial(5)) # Output: 120

6■■ Find the Largest Element in a List

def find_max(lst):
return max(lst)

print(find_max([3, 7, 2, 9, 5])) # Output: 9

You might also like