Home/python/Page 3
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What are relational operators, assignment operators, and membership operators?
The purpose of relational operators is to compare values. The assignment operators in Python can help in combining all the arithmetic operators with the assignment symbol. Membership operators in Python with the purpose to validate the membership of a value in a sequence.
How are identity operators different from membership operators?
Unlike membership operators, the identity operators compare the values to find out if they have the same value or not.
Unlike membership operators, the identity operators compare the values to find out if they have the same value or not.
See lessWhat are Python decorators?
A specific change made in Python syntax to alter the functions easily are termed as Python decorators.
A specific change made in Python syntax to alter the functions easily are termed as Python decorators.
See lessDifferentiate between list and tuple.
Tuple is not mutable it can be hashed eg. key for dictionaries. On the other hand, lists are mutable.
Tuple is not mutable it can be hashed eg. key for dictionaries. On the other hand, lists are mutable.
See lessDescribe multithreading in Python.
Using Multithreading to speed up the code is not the go-to option, even though Python comes with a multi-threading package. The package has the GIL or Global Interpreter Lock, which is a construct. It ensures that only one of the threads executes at any given time. A thread acquires the GIL and perfRead more
Using Multithreading to speed up the code is not the go-to option, even though Python comes with a multi-threading package.
The package has the GIL or Global Interpreter Lock, which is a construct. It ensures that only one of the threads executes at any given time. A thread acquires the GIL and performs work before passing it to the next thread.
This happens so fast that to a user it seems that threads are executing in parallel. Obviously, this is not the case as they are just taking turns while using the same CPU core. GIL passing adds to the overall overhead of the execution.
As such, if you intend to use the threading package for speeding up the execution, using the package is not recommended.
See lessDraw a comparison between the range and xrange in Python.
In terms of functionality, both range and xrange are identical. Both allow for generating a list of integers. The main difference between the two is that while range returns a Python list object, xrange returns an xrange object. Xrange is not able to generate a static list at runtime the way range dRead more
In terms of functionality, both range and xrange are identical. Both allow for generating a list of integers. The main difference between the two is that while range returns a Python list object, xrange returns an xrange object.
Xrange is not able to generate a static list at runtime the way range does. On the contrary, it creates values along with the requirements via a special technique called yielding. It is used with a type of object known as generators.
If you have an enormous range for which you need to generate a list, then xrange is the function to opt for. This is especially relevant for scenarios dealing with a memory-sensitive system, such as a smartphone.
The range is a memory hog. Using it requires much more memory, especially if the requirement is gigantic. Hence, in creating an array of integers to suit the needs, it can result in a memory error and ultimately lead to a crash.
See lessWhat is the difference between deep copy and shallow copy?
We use a shallow copy when a new instance type gets created. It keeps the values that are copied in the new instance. Just like it copies the values, the shallow copy also copies the reference pointers. Reference points copied in the shallow copy reference to the original objects. Any changes made iRead more
We use a shallow copy when a new instance type gets created. It keeps the values that are copied in the new instance. Just like it copies the values, the shallow copy also copies the reference pointers.
Reference points copied in the shallow copy reference to the original objects. Any changes made in any member of the class affect the original copy of the same. Shallow copy enables faster execution of the program.
Deep copy is used for storing values that are already copied. Unlike shallow copy, it doesn’t copy the reference pointers to the objects. Deep copy makes the reference to an object in addition to storing the new object that is pointed by some other object.
Changes made to the original copy will not affect any other copy that makes use of the referenced or stored object. Contrary to the shallow copy, deep copy makes the execution of a program slower. This is due to the fact that it makes some copies for each object that is called.
See lessHow do you distinguish between NumPy and SciPy?
Typically, NumPy contains nothing but the array data type and the most basic operations, such as basic element-wise functions, indexing, reshaping, and sorting. All the numerical code resides in SciPy. As one of NumPy’s most important goals is compatibility, the library tries to retain all featuresRead more
Typically, NumPy contains nothing but the array data type and the most basic operations, such as basic element-wise functions, indexing, reshaping, and sorting. All the numerical code resides in SciPy.
As one of NumPy’s most important goals is compatibility, the library tries to retain all features supported by either of its predecessors. Hence, NumPy contains a few linear algebra functions despite the fact that these more appropriately belong to the SciPy library.
SciPy contains fully-featured versions of the linear algebra modules available to NumPy in addition to several other numerical algorithms.
See less