Essential Python Interview Questions: Day 1 Insights
Key Concepts and Practical Examples for Python Beginners
What are local variables and global variables in Python?
Global Variables: Variables declared outside a function or in a global space are called global variables. These variables can be accessed by any function in the program.
Local Variables: Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.
When to use a tuple vs list vs dictionary in Python?
Use a
tuple
to store a sequence of items that will not change.Use a
list
to store a sequence of items that may change.Use a
dictionary
when you want to associate pairs of two items.
Explain some benefits of Python
Python is a dynamic-typed language. It means that you don’t need to mention the data type of variables during their declaration.
Python supports object-orientated programming as you can define classes along with the composition and inheritance.
Functions in Python are like first-class objects. It suggests you can assign them to variables, return from other methods and pass them as arguments.
Developing using Python is quick but running it is often slower than compiled languages.
Python has several usages like web-based applications, test automation, data modeling, big data analytics, and much more.
What is Lambda Functions in Python?
A Lambda Function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression.
Consider:
x = lambda a : a + 10
print(x(5)) # Output: 15