Found 10476 Articles for Python

isupper(), islower(), lower(), upper() in Python and their applications

Pavitra
Updated on 03-Jul-2020 07:51:06

2K+ Views

In this article, we will learn about isupper(), islower() ,upper() , lower() function in Python 3.x. or earlier.These are the functions that can be used on strings and related types. They are included in Python Standard Library.All the functions accept no arguments. The isupper() & islower() return boolean values whereas the upper() & lower() function returns strings either in uppercase or lowercase.Now let’s see the implementation using an exampleExamplestring = 'tutorialspoint' # checking for uppercase characters print(string.isupper()) # checking for lowercase characters print(string.islower()) # convert to uppercase characters print(string.upper()) # convert to lowercase characters print(string.lower())OutputFalse True ... Read More

Ascii() in python

Pradeep Elance
Updated on 07-Aug-2019 07:50:08

1K+ Views

ASCII is abbreviated from of American Standard Code for Information Interchange. It is a character encoding standard. For example the ASCII value of English alphabet A is 65. Python provides this function to get the printable representation of an object. It takes one parameter which is an object that can be a list, strings, tuple etc. The output of the function is the hex representation. The non-ascii characters can be escaped using \x, \u or \U escapes.SyntaxThe syntax is −Syntax: ascii(object)ExamplePrinting strings with individual characters and multiple characters.# Individual Characters print(ascii("Ω")) print(ascii("θ")) # A string int multiple characters print(ascii("TΨtΦrial"))OutputRunning the ... Read More

isdisjoint() function in Python

Pavitra
Updated on 03-Jul-2020 07:53:20

243 Views

In this article, we will learn about how we can implement isdisjoint() function on set() data type. This function checks whether the sets passed as arguments have any element in common . In case any element is found, False is returned and True otherwise.The isdisjoint() function can take lists, tuples & dictionaries as input arguments in addition to set inputs. THses types are implicitly converted to set type by the Python interpreter.Syntax.isdisjoint()Return valueBoolean True/FalseNow let’s consider an illustration related to the implementationExample#declaration of the sample sets set_1 = {'t', 'u', 't', 'o', 'r', 'i', 'a', 'l'} set_2 = {'p', 'o', ... Read More

intersection_update() in Python to find common elements in n arrays

Pavitra
Updated on 07-Aug-2019 07:43:42

190 Views

In this article, we will learn about the iintersection_update() in Python to find out common elements in n arrays.The problem is that we are given an array containing lists, find all common elements in given arrays?Algorithm1.Initializingres with the first list inside the array 2.Iterating through the array containing lists 3.Updating the res list by applying intersection_update() function to check the common elements. 4.Finally returning the list and display the output by the help of the print statement.Now let’s take a look at its implementationExampledef commonEle(arr): # initialize res with set(arr[0]) res = set(arr[0]) # new value will get ... Read More

Intersection() function Python

Pavitra
Updated on 03-Jul-2020 07:54:35

248 Views

In this article, we will learn about intersection() function that can be performed on any given set. According to mathematics intersection means finding out common elements from the two sets.Syntax.intersection( ……..)Return Value common elements in sets passed as arguments.Exampleset_1 = {'t', 'u', 't', 'o', 'r', 'i', 'a', 'l'} set_2 = {'p', 'o', 'i', 'n', 't'} set_3 = {'t', 'u', 't'} #intersection of two sets print("set1 intersection set2 : ", set_1.intersection(set_2)) # intersection of three sets print("set1 intersection set2 intersection set3 :", set_1.intersection(set_2, set_3))Outputset1 intersection set2 : {'i', 'o', 't'} set1 intersection set2 intersection set3 : {'t'}Explanation Here a search is made ... Read More

append() and extend() in Python

Pradeep Elance
Updated on 07-Aug-2019 07:39:41

1K+ Views

The append() and extend() functions are used with the python list to increase its number of elements. But the two have different behaviors as shown below.append()Syntax: list_name.append(‘value’) It takes only one argument.This function appends the incoming element to the end of the list as a single new element. Even if the incoming element is itself a list, it will increase the count of the original list by only one.Examplelist = ['Mon', 'Tue', 'Wed' ] print("Existing list", list) # Append an element list.append('Thu') print("Appended one element: ", list) # Append a list list.append(['Fri', 'Sat']) print("Appended a list: ", list)OutputRunning the ... Read More

The intersection of two arrays in Python (Lambda expression and filter function )

Pavitra
Updated on 07-Aug-2019 07:32:56

713 Views

In this article, we will learn about the intersection of two arrays in Python with the help of Lambda expression and filter function.The problem is that we are given two arrays we have to find out common elements in both of them.Algorithm1. Declaring an intersection function with two arguments. 2. Now we use the lambda expression to create an inline function for selection of elements with the help of filter function checking that element is contained in both the list or not. 3. Finally, we convert all the common elements in the form of a list by the help of ... Read More

Add a row at top in pandas DataFrame

Pradeep Elance
Updated on 07-Aug-2019 07:33:33

2K+ Views

In Pandas a DataFrame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. We can create a DataFrame using list, dict, series and another DataFrame. But when we want to add a new row to an already created DataFrame, it is achieved through a in-built method like append which add it at the end of the DataFrame. In this article we will find ways to add the new row DataFrame at the top of the DataFrame using some tricks involving the index of the elements in the DataFrame.ExampleLet's first create a new ... Read More

Inplace Operators in Python - ixor(), iand(), ipow()

Pavitra
Updated on 07-Aug-2019 07:27:12

262 Views

In this article, we will learn about some of the inplace operators available in Python 3.x. Or earlier.Python provides methods to perform inplace operations, i.e assignment and computation simultaneously using in a single statement with the help of “operator” module. Here we will discuss about ixor(), iand(), ipow() functions .ixor()This function allows us to assign and xor current value. This operation behaves like “a^=b” operation. Assigning can’t be performed in case of immutable data types, such as strings and tuples.Exampleimport operator as op # using ixor() to xor int1 = op.ixor(786, 12); # displaying value print ("The value ... Read More

Absolute and Relative frequency in Pandas

Pradeep Elance
Updated on 03-Jul-2020 07:45:19

840 Views

In statistics, the term "frequency" indicates the number of occurrences of a value in a given data sample. As a software meant for mathematical and scientific analysis, Pandas has many in-built methods to calculate frequency from a given sample.Absolute Frequency It is same as just the frequency where the number of occurrences of a data element is calculated. In the below example, we simply count the number of times the name of a city is appearing in a given DataFrame and report it out as frequency.Approach 1 − We use the pandas method named .value_counts.Exampleimport pandas as pd # Create ... Read More

Advertisements