DEV Community

Fatima Alam
Fatima Alam

Posted on • Edited on

Python Interview Questions

Python Lists are mutable
Points to remember ->
1) The list variable always stores a reference to that list and so if it is assigned to any other variable the changes made later on to the first variable will be carried on to then new one because it doesn't store a copy but the reference.

Image description

Tuples
Tuples are immutable.

For Loop

Image description

Set
Used for lookups to get true or false if a particular element exists or not.

And for non empty set x = {1,2,3} works
But, to create an empty set -> x = set() because x = {} will create a dictionary instead.

Packing and Unpacking in python

Image description

Works with dictionaries as well

Image description

Exceptions

Image description

Try catch

Image description

Lambda function

Image description

Map with Lambda function

Image description

Filter with Lambda function

What is the difference between .py and .pyc files?
.py files contain the source code of a program. Whereas, .pyc file contains the bytecode of your program. We get bytecode after compilation of .py file (source code). .pyc files are not created for all the files that you run. It is only created for the files that you import.
Before executing a python program python interpreter checks for the compiled files. If the file is present, the virtual machine executes it. If not found, it checks for .py file. If found, compiles it to .pyc file and then python virtual machine executes it.
Having .pyc file saves you the compilation time.

Top comments (0)