5 Python Programming Language Interview Questions

Below are 5 simple Python Programming Language questions which can be asked in a Python Related job interview.

Q. 1 – Write a Python Program to count occurrences of characters in a word.

import collections

counters = collections.Counter("Computer")

# Prints out Counter({'C': 1, 'o': 1, 'm': 1, 'p': 1, 'u': 1, 't': 1, 'e': 1, 'r': 1})

Q. 2 – Write a Simple Lambda Expression?

sumlambda = lambda x, y : x + y
print(sumlambda(4, 5))

Q. 3 – What is filter keyword in Python Programming Language?

The filter function is a utility function which can skip values based on some condition.

a_list = [3, 4, 5, 6, 7, 8, 9]
for i in filter(lambda x: x % 2 == 0, a):

Q. 4 – Explain Reading/Writing Files in Python Programming Language?

Writing a File in Python

f = open('hello.txt','w')                  # opens a file in write mode
f.write('ComputerScienceHub Website')     # writes this line in file
f.close()                                 # closes the file

Reading a File in Python

f =open('hello.txt','r') 		# opens a file in read mode
text = f.read() 				# reads the entire contents of file in memory
print(text) 					# prints the read text
f.close()                       # closes the file

Q. 5 – Best way to read a File in Python?

with open("hello.txt", "r") as f:       
	for line in f:

Above code block after it ends will automatically close file hello.txt without programmer need to explicitly do it using f.close()


Hi, there I'm founder of ComputerScienceHub(Started this to bring useful Computer Science information just at one place). Personally I've been doing JavaScript, Python development since 2015(Been long) - Worked upon couple of Web Development Projects, Did some Data Science stuff using Python. Nowadays primarily I work as Freelance JavaScript Developer(Web Developer) and on side-by-side managing team of Computer Science specialists at ComputerScienceHub.io

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts