Pradeep Elance has Published 498 Articles

Different ways to clear a list in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:27:03

4K+ Views

Clearing up all the elements in a python list can be done in many ways. Below are the some of the methods which are implemented to achieve this.using clear()This function is a part of standard library and empties the python list completely.Syntax: list_name.clear() list_name is the name of the list ... Read More

delattr() and del() in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:22:01

257 Views

These two functions are used to remove attributes from classes. The delattr() allows dynamoc deletion of attribute while the del() is more efficient explicit in deleting the attribute.Using delattr()Syntax: delattr(object_name, attribute_name) Where object name is the name of the object, instantiated form the class. Attribute_name is the name of the ... Read More

Count frequencies of all elements in array in Python using collections module

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:18:37

188 Views

As python allows duplicate elements in a list we can have one element present multiple Times. The frequency of elements in a list indicates how many times an element occurs in a list. In this article we use the Counter function of the collections module to find out the frequency ... Read More

Count distinct elements in an array in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:15:52

385 Views

In a list in Python we may have duplicate elements. When we count the length of the list we get the total length including the duplicate elements. But in this article we will see how to get the total count of the distinct elements or unique elements in a list.ExampleIn ... Read More

Comparing dates in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:13:45

389 Views

Comparing dates and times is a very crucial requirement in any programming language. Python has a datetime library which has many inbuilt functions to use date and time. Interestingly date and time can also be compared like mathematical comparison between various numbers.ExampleIn the below example we have chosen to dates ... Read More

casefold() string in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:10:47

74 Views

This function is helpful in converting the letters of a word into lowercase. When applied to two strings it can match their values irrespective of the type up of the case of the letters.Applying casefold()The below example we apply the casefold() function to a string and the result comes out ... Read More

Capitalize first letter of a column in Pandas dataframe

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:09:11

760 Views

A pandas dataframe is similar to a table with rows and columns. Sometimes we may have a need of capitalizing the first letters of one column in the dataframe which can be achieved by the following methods.Creating a DataframeIn the below example we first create a dataframe with column names ... Read More

callable() in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:05:13

156 Views

The callable() function in python is part of its standard library which returns true if the object is callable and returns false if it is not.The object itself should have a call method to be callable. For example if we just declare a variable with value, it is not callable, ... Read More

The Byte Objects vs String in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:01:45

329 Views

As computers can only store bytes of data, we need to convert various data formats in byte data format. For example images to become bytes, are stored with PNG, JPEG etc. Similarly music is stored as .WAV, .MP3 etc. The software responsible for creating and managing this formats do the ... Read More

bool() in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 07:59:15

108 Views

The bool() in python returns a boolean value of the parameter supplied to it. The parameter can be any of the following and the results are as per the below conditions. Except the values mentioned here the remaining values return True.False is returned when the parameter value passed is as ... Read More

Advertisements