Get Latest Exam Updates, Free Study materials and Tips
Q1. What is the difference between lists and tuples in Python?
Q2. Python is an interpreted language. Explain.
Ans: An interpreted language is any programming language that is not in machine-level code before runtime. Therefore, Python is an interpreted language.
Q3. What is PYTHONPATH?
Ans: It is an environment variable that is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.
Q4. What are local variables and global variables in Python?
Ans: 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.
Q5. What is the difference between Python Arrays and lists?
Ans: Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type element whereas lists can hold any data type elements.
Q6. What is self in Python?
Ans: Self is an instance of an object of a class. In Python, this is explicitly included as the first parameter. However, this is not the case in Java where it’s optional. It helps to differentiate between the methods and attributes of a class with local variables.
The self-variable in the init method refers to the newly created object while in other methods, it refers to the object whose method was called.
Q7. What is pickling and unpickling?
Ans: The pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.
Q8. What does this mean: *args, **kwargs? And why would we use it?
Ans: We use *args when we aren’t sure how many arguments are going to be passed to a function, or if we want to pass a stored list or tuple of arguments to a function. **kwargs is used when we don’t know how many keyword arguments will be passed to a function, or it can be used to pass the values of a dictionary as keyword arguments. The identifiers args and kwargs are a convention, you could also use *bob and **billy but that would not be wise.
Q9. How to overload constructors or methods in Python?
Python’s constructor: _init__ () is the first method of a class. Whenever we try to instantiate an object __init__() is automatically invoked by python to initialize members of an object. We can’t overload constructors or methods in Python. It shows an error if we try to overload.
Q.10 What is the difference between deep and shallow copy?
Ans: Shallow copy is used when a new instance type gets created and it keeps the values that are copied in the new instance. Shallow copy is used to copy the reference pointers just like it copies the values. These references point to the original objects and the changes made in any member of the class will also affect the original copy of it. Shallow copy allows faster execution of the program and it depends on the size of the data that is used.
Deep copy is used to store the values that are already copied. Deep copy doesn’t copy the reference pointers to the objects. It makes the reference to an object and the new object that is pointed by some other object gets stored. The changes made in the original copy won’t affect any other copy that uses the object. Deep copy makes execution of the program slower due to making certain copies for each object that is been called.
Q.11 What is swapcase() function in Python?
Ans: It is a string’s function which converts all uppercase characters into lowercase and vice versa. It is used to alter the existing case of the string. This method creates a copy of the string which contains all the characters in the swap case. If the string is in lowercase, it generates a small case string and vice versa. It automatically ignores all the non-alphabetic characters. See an example below.
Q.12 Difference between generators and iterators?
Ans: In Python, iterators are used to iterate over a group of elements (in a list, for example). The way of implementing these iterators is known as generators. It yields an expression in the function, but otherwise behaves like a normal function.
Q.13 What is GIL?
Ans: GIL or the Global Interpreter Lock is a mutex, used to limit access to Python objects. It synchronizes threads and prevents them from running at the same time
Q.14 What is PYTHONPATH?
Ans: PYTHONPATH is an environment variable that is used to incorporate additional directories when a module/package is imported. Whenever a module/package is imported, PYTHONPATH is used to check if the imported modules are present in the existing directories. Usually, the interpreter uses PYTHONPATH to determine which module to load.
Q.15 What is an Expression?
Ans: An expression Can be defined as a combination of variables, values operators a call to functions. It is a sequence of operands or operators like a + B – 5 is called an expression. Python supports many such operators for combining data object into an express.
Q.16 Discuss Django Architecture.
Ans: Django is a web service used to build your web pages. Its architecture is as shown:
Q.17 How Do You Display the Contents of a Text File in Reverse Order?
Ans: You can display the contents of a text file in reverse order using the following steps:
Q.18 What is the difference between xrange and range?
Ans: Xrange returns the xrange object while range returns the list and uses the same memory and no matter what the range size is.
Q.19 Explain Flask and its benefits
Ans: Flask is a web microframework for Python based on “Werkzeug, Jinja 2 and good intentions” BSD licensed. Werkzeug and jingja are two of its dependencies.
Flask is part of the micro-framework. Which means it will have little to no dependencies on external libraries. It makes the framework light while there is a little dependency to update and less security bugs.
Q.20 Explain how you can access sessions in Flask?
Ans: A session basically allows you to remember information from one request to another. In a flask, it uses a signed cookie so the user can look at the session contents and modify. The user can modify the session if only it has the secret key Flask.secret_key.
Q.21 If you have multiple Memcache servers, and one of them fails that contain data, will it try to get them?
Ans: The data in the failed server won’t get removed, but there is a provision for auto-failure, which you can configure for multiple nodes. Fail-over can be triggered during any kind of socket or Memcached server level errors and not during normal client errors like adding an existing key, etc.
Q.22 Explain what is Dogpile effect? How can you prevent this effect?
Ans: Dogpile effect is referred to the event when the cache expires, and websites are hit by the multiple requests made by the client at the same time. This effect can be prevented by using a semaphore lock. In this system, when the value expires, the first process acquires the lock and starts generating a new value.
Q.23 What is enumerate() in Python?
Ans: Enumerate() in Python is a built-in function used for assigning an index to each item of the iterable object. It adds a loop on the iterable objects while keeping track of the current item and returns the object in an enumerable form. This object can be used in a for loop to convert it into a list by using list() method
Q.24What is scope resolution?
Ans: A scope is a block of code where an object in Python remains relevant. Each and every object of python functions within its respective scope. As Namespaces uniquely identify all the objects inside a program but these namespaces also have a scope defined for them where you could use their objects without any prefix. It defines the accessibility and the lifetime of a variable.
Prepare For Your Placements: https://lastmomenttuitions.com/courses/placement-preparation/
/ Youtube Channel: https://www.youtube.com/channel/UCGFNZxMqKLsqWERX_N2f08Q
Follow For Latest Updates, Study Tips & More Content!
Not a member yet? Register now
Are you a member? Login now