Showing posts with label PROGRAMMING. Show all posts
Showing posts with label PROGRAMMING. Show all posts

Tuesday, July 14, 2020

What is the difference between a Shallow copy and deep copy?

SMART SUBU


What is the difference between a Shallow copy and deep copy

 

In Python, if we want to go for faster execution of the program, depending on the size of the data, a shallow copy is preferred, where it is used as a reference pointer which copies the values by referring to the original objects and changes are made in any of the members of the class but the original copy is not affected by it.

 

Whereas, the deep copy concept in Python is used to store the values that are already copied. The reference pointers are not copied into the objects in case of deep copy, but it makes the reference to an object and the new object that is pointed by some other objects are stored.

 

Changes made in the original copy will not affect the other copy that is used in the object. With the application of deep copy concept, the execution of the program become slower, because of multiple copies of the same object that needs to be called for execution of the program again and again.

 

So, in nutshell, we can say that shallow copy helps in faster execution of the program without disturbing the original copy, whereas deep copy makes multiple copies of reference of references into new memory locations of the same instance and thus results in in slow execution of the program.

Monday, July 13, 2020

What are List and Tuples in Python?

SMART SUBU


What are List and Tuples in Python

In Python, List and Tuples both are data structures. In case of List, we can include integers, as well as characters, in the data structure and the values in the List, can be edited or altered, in technical terms, it is known as mutability.

Whereas in the case of Tuples, characters and integers are included, but those cannot be edited, hence only they are immutable. But, the question which comes in mind is that if List and Tuples have the same characteristics of data structure, why we need two types of data structure.

Why we need two types of data structure

When there is a requirement of a fixed data structure which cannot be altered throughout the scripting of the program we can safely use Tuple. But, if we need a dynamic data structure which can be altered and edited as required during the scripting process of the programming, List is more preferable.

 So in order to meet the requirement of the programming and to make the scripting efficient, either List or Tuples are used. Tuples are preferred in a memory-intensive task, whereas, List is preferred in case of buffers. When we are sure about the number of columns in a data structure we should select Tuple and when we are not we should go for List.

If you are interested in Computer Programming, You can mail at smartsubu2020@gmail.com.

Sunday, July 12, 2020

What is GIL in python?

SMART SUBU
Impact of Artificial Intelligence


There are two concepts in python, one is threading and the other one is the processor. In order to speed up the execution of the code in python, multi-threading package is used in python. Global Interpreter Lock (GIL) is a construct in python which ensures that only one thread is executed at a time while running the code.

The mode of operation of GIL is that a particular thread acquires the GIL, execution is done and then the GIL is passed into the next thread.

It may seem that the threads are executed in parallel, but, actually, each of the threads are executed singly and thus GIL adds to the overhead while execution of a particular programme.

It is a process of multi-threading using the CPU core by taking individual threads at a time. GIL should be used based on the context of the programming and the number of core processor present on the computer.

If You are interested in Computer Programming, You can mail to smartsubu2020@gmail.com.

 

Friday, July 10, 2020

What is Ternary operator in python?

SMART SUBU


What is Ternary operator in python

The ternary operator is used for the evaluation of the statement. Conditional statements are shown with the help of the ternary operator.

The operator consists of true or false values along with the statement which needs to be evaluated. 

The ternary operator evaluates the statement and checks for the condition, if the condition is fulfilled then the assigned value is returned and if the condition turns out to be false then the alternate value is returned.

Thursday, July 9, 2020

What is monkey patching?

SMART SUBU


 

What is monkey patching

Monkey patching is a process of forcing a function into a function of a particular class in real run time. It is the process of applying the patch in a dynamic way to bring a change in the class. 

It can be done by creating a function which is new and not a part of the class but we can force the function into any class with the help of monkey patch.

It is used as a quick fix to alter the issues in the code without creating any new class at run time. Monkey patching is done by creating patches to add dynamic attributes in a class at run time.

Tuesday, July 7, 2020

How Randomization of items is done in List of python

SMART SUBU
How Randomization of items is done in List of python

Randomization of items in python can be done by importing a function called shuffle from the dictionary called random. 

First of all, we create a List. We define the list and then use the shuffle command with the name of the list and thus items in the list are shuffled every time the function is called.

If you are interested to know more about Python, you can mail to smartsubu2020@gmail.com.

 

 

 

Monday, July 6, 2020

What are split() sub() and subn() in python

SMART SUBU


What are split() sub() and subn() in python

The data structure string is modified with the help of the "re" module in python. In the module, three methods are used. When for modification regex pattern is used to split a given string into a list spilt() is used.

When the method finds all the substrings where the regex pattern matches and then replace them with a different string, the sub() command is used.

The command subn() is similar to sub()  and also returns the new string along with the number of replacements.