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…

What is the difference between deep and shallow copy?

What is the difference between deep and shallow copy?

What is the difference between deep and shallow copy? Shallow copy and deep copy are basically used for copying data between objects. To exactly know about the difference between deep and shallow copy let’s talk about the main usage of deep and shallow copy in python that will surely help you to deeply understand the differences between these two copies. Shallow Copy In Python A shallow copy creates a new object and then copies the non-static fields of the recent object to the innovative object. During the shallow copy, a position of the object is copied into other objects. In…

What Is The Usage Of Help() And Dir() Function In Python?

What Is The Usage Of Help() And Dir() Function In Python?

What Is The Usage Of Help() And Dir() Function In Python? Python is becoming the imperative language to learn because of its prosperous ecosystem. It can be used for web development, scientific computing, and artificial intelligence, almost for everything. The user-friendly syntax makes this language easier and allows programmers to convey their idea in fewer lines as compared to the other programming languages. This multi-paradigm language is supportive of big organizations.  Keen learning of python language contains many aspects including its libraries, tools, objects, functions, and others. The usage of all these elements makes this language much fruitful and functional…

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: # monk.py  class…

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:   From re import…