Python Coding Interview Questions and Answers
The Best LIVE Mock Interview - You should go through before Interview
Freshers / Beginner level questions & answers
Ques 1. Write a function to reverse a string.
def reverse_string(input_str):
return input_str[::-1]
Example:
reverse_string('hello') # Output: 'olleh'
Is it helpful?
Add Comment
View Comments
Ques 2. Implement a function to check if a string is a palindrome.
def is_palindrome(input_str):
return input_str == input_str[::-1]
Example:
is_palindrome('radar') # Output: True
Is it helpful?
Add Comment
View Comments
Ques 3. Write a Python function to check if a given year is a leap year.
def is_leap_year(year):
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
Example:
is_leap_year(2024) # Output: True
Is it helpful?
Add Comment
View Comments
Ques 4. Implement a function to find the maximum element in a list.
def find_max_element(lst):
return max(lst)
Example:
find_max_element([3, 7, 2, 8, 5]) # Output: 8
Is it helpful?
Add Comment
View Comments
Ques 5. Write a Python program to count the occurrences of each element in a list.
from collections import Counter
def count_occurrences(lst):
return Counter(lst)
Example:
count_occurrences([1, 2, 1, 3, 2, 4, 1]) # Output: {1: 3, 2: 2, 3: 1, 4: 1}
Is it helpful?
Add Comment
View Comments
Ques 6. Create a function to check if a given string is an anagram of another string.
def is_anagram(str1, str2):
return sorted(str1) == sorted(str2)
Example:
is_anagram(\'listen\', \'silent\') # Output: True
Is it helpful?
Add Comment
View Comments
Ques 7. Implement a function to remove duplicates from a list.
def remove_duplicates(lst):
return list(set(lst))
Example:
remove_duplicates([1, 2, 2, 3, 4, 4, 5]) # Output: [1, 2, 3, 4, 5]
Is it helpful?
Add Comment
View Comments
Most helpful rated by users:
- Implement a function to find the maximum element in a list.
- Write a Python program to count the occurrences of each element in a list.
- Write a function to reverse a string.
- Implement a function to check if a string is a palindrome.
- Write a Python function to check if a given year is a leap year.
Related interview subjects
C++ interview questions and answers - Total 142 questions |
VBA interview questions and answers - Total 30 questions |
COBOL interview questions and answers - Total 50 questions |
R Language interview questions and answers - Total 30 questions |
Python Coding interview questions and answers - Total 20 questions |
Scala interview questions and answers - Total 48 questions |
Swift interview questions and answers - Total 49 questions |
Golang interview questions and answers - Total 30 questions |
Embedded C interview questions and answers - Total 30 questions |