What is the Difference between List and Tuples?

What is the Difference between List and Tuples?

What is the Difference between List and Tuples? Do you want to know the exact difference between Tuple and List in python? Well, before we talk about the difference between both just have a quick look at the role of tuple and lists in python. The list is the most strong and beneficial tool in python that does not need to be always homogenous like other languages. This tool is mainly utilized to store an ordered collection of various items, which might be similar. A list includes strings, integers, and objects. To create a list all the elements should be…

Whenever Python exists, why isn’t all the memory de-allocated?

Whenever Python exists, why isn’t all the memory de-allocated?

Whenever Python exists, why isn’t all the memory de-allocated? Ans. Using ‘del’ keyword we can try to remove some particular object. But Python is a ‘garbage collector’ that means there is no guarantee that the object is actually removed from the memory when you use ‘Del some Big Object’. In fact ‘Del some Big Object’ is not only pointless but also it is a bad style. According to ‘Python official documentation’ you can force the garbage collector to release referring memory with gc.collect().  It is known, where Python will definitely leak memory when you declare circular references in your object…

What is monkey patching in python?

What is monkey patching in python?

What is monkey patching in python? Python is a dynamic programming language and therefore the classes in python are mutable so that you can reopen them, modify, or even replace them. In simple words, monkey patching is making changes to a module or class while the program is running. It refers to reopening the existing classes or methods in class at runtime and changing their behavior according to the requirement. This code can be used whenever you need it. A Monkey Patch is a piece of Python code which extends or modifies other code at runtime. Example:

  We…

What do these words mean in python: *args, **kwargs? And why would we use it?

What do these words mean in python: *args, **kwargs? And why would we use it?

What do these words mean in python: *args, **kwargs? And why would we use it? *args The *args keyword in python is used to pass a variable number of arguments to a function. It is mainly used to pass a non-keyworded, variable length argument list. The *args keyword allows you to take more arguments than the number of formal arguments which were previously defined by you. By this keyword, any number of extra arguments can be tacked on to your current formal parameters. Example:  If we want to make a multiply function that takes any number of arguments and be…

Python Coding

Python Coding

Write a one-liner that will count the number of capital letters in a file. Your code should work even if the file is too big to fit in memory. for i in string : (i.isupper()) : count = count + 1 where, string is the input which is taken from the user. isupper() is a function which checks whether the alphabet is uppercase or not. Count is a variable which increments itself whenever it finds an upper case alphabet.    

What are negative indexes and why are they used?

What are negative indexes and why are they used?

What are negative indexes and why are they used? As we know, indexes are used in arrays in all the programming languages. We can access the elements of an array by going through their indexes. But no programming language allows us to use a negative index value such as -4. Python programming language supports negative indexing of arrays, something which is not available in arrays in most other programming languages. This means that the index value of -1 gives the last element, and -2 gives the second last element of an array. The negative indexing starts from where the array…

What are dictionaries in python?

What are dictionaries in python?

What are dictionaries in python? A collection which is unordered, changeable and indexed is known as a dictionary in python. It takes two elements where one is the key and the other one is value. However, the keys should be unique within a dictionary while values may not be. The data type of the values can be anything but the keys must be of an immutable data type such as strings, numbers, or tuples. Syntax : To separate a key from its value a colon (:) is used whereas the items are separated by commas. The whole thing is enclosed…

Explain split(), sub(), subn() methods of “re” module in Python.

Explain split(), sub(), subn() methods of “re” module in Python.

Explain split(), sub(), subn() methods of “re” module in Python The re module in python refers to the module Regular Expressions (RE). It specifies a set of strings or patterns that matches it. Metacharacters are used to understand the analogy of RE. Function split() This function splits the string according to the occurrences of a character or a pattern. When it finds that pattern, it returns the remaining characters from the string as part of the resulting list.  The split method should be imported before using it in the program. Syntax:    re.split (pattern, string, maxsplit=0, flags=0) Example:  

Function sub()…

Write a sorting algorithm for a numerical dataset in Python.

Write a sorting algorithm for a numerical dataset in Python.

Write a sorting algorithm for a numerical dataset in Python.   Sorting refers to arranging the given data in a particular format. A sorting algorithm specifies the way to arrange data in a particular format and order. It makes the data more readable and the data searching can be optimized to a very high level. There are many kinds of sorting algorithms in python. These are:  1. Bubble sort  2. Merge sort  3. Insertion sort  4. Shell sort 5.  Selection sort A sorting algorithm for a given numerical dataset is given below:

This is a comparison based algorithm where…

What is the process of compilation and linking in python?

What is the process of compilation and linking in python?

What is the process of compilation and linking in python? Compilation The source code in python is saved as a .py file which is then compiled into a format known as byte code. Compilation is simply a translation step. Byte code is a lower level and platform independent machine code which represents your source code. After the compilation, the code is stored in .pyc files and is regenerated when the source is updated or when it is necessary to do so. This process is known as compilation. Linking The byte code in the .pyc file is then loaded into the…