Python Articles

Page 789 of 852

Binding function in Python Tkinter

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 2K+ Views

In python tkinter is a GUI library that can be used for various GUI programming. Such applications are useful to build desktop applications. In this article we will see one aspect of the GUI programming called Binding functions. This is about binding events to functions and methods so that when the event occurs that specific function is executed.Binding keyboard eventIn the below example we bind the press of any key from the keyboard with a function that gets executed. Once the Tkinter GUI window is open, we can press any key in the keyboard and we get a message that ...

Read More

Python Get a list as input from user

Pradeep Elance
Pradeep Elance
Updated on 09-Jul-2020 10K+ Views

In this article we will see you how to ask the user to enter elements of a list and finally create the list with those entered values.With format and inputThe format function can be used to fill in the values in the place holders and the input function will capture the value entered by the user. Finally, we will append the elements into the list one by one.ExamplelistA = [] # Input number of elemetns n = int(input("Enter number of elements in the list : ")) # iterating till the range for i in range(0, n):    print("Enter element No-{}: ...

Read More

Converting an image to ASCII image in Python

Pradeep Elance
Pradeep Elance
Updated on 09-Jul-2020 668 Views

In this article we we want to convert a given images into a text bases image also called ASCII image.Below is the Python program which will take an input imagee and various functions to convert them into grayscale picture and then apply the ASCII characters to create different patterns insert the image. Finally the emails comes text based image this is a series of plane ASCII characters.Examplefrom PIL import Image import os ASCII_CHARS = [ '#', '?', '%', '.', 'S', '+', '.', '*', ':', ', ', '@'] def resize_image(image, new_width=25):    (input__width, input__height) = image.size    aspect_ratio = input__height/float(input__width)   ...

Read More

Python Grouped Flattening of list

Hafeezul Kareem
Hafeezul Kareem
Updated on 07-Jul-2020 220 Views

In this tutorial, we are going to write a program that flattens a list that contains sub-lists. Given number flatten the sublists until the given number index as parts. Let's see an example to understand it clearly.Inputlists = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] number = 2Output[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]Let's see the steps to solve the problem.Initialize the list and number.Initialize an empty list.Iterate over the list with range(0, len(lists), number.Get the sublists using slicing lists[i:number].Iterate over the sublists and append the resultant list to the result list.Print the result.Example# ...

Read More

Mathematical Functions in Python - Special Functions and Constants

Pavitra
Pavitra
Updated on 03-Jul-2020 386 Views

In this article, we will learn about special functions and constants available in the math module in the Python Standard Library.Here we will discuss some constants like −pieinfNantauAnd some functions likeGammaIsinfIsnanisfinite()erf()Let's discuss constants and their respective values −pi3.141592…..e2.718281…...inf6.283185…...nantauNow let’s discuss some special functions and their implementation −Gamma − return the value of gamma(n)Isinf − checks whether the value of the function is infinity or not.Isnan − check whether the return value is a number or not.Isfinite − return True if the value is neither an infinity or a nan false otherwiseErf − returns the error function of x.Now let;’s take ...

Read More

Intersection() function Python

Pavitra
Pavitra
Updated on 03-Jul-2020 306 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

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

Pavitra
Pavitra
Updated on 03-Jul-2020 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

A += B Assignment Riddle in Python

Pradeep Elance
Pradeep Elance
Updated on 03-Jul-2020 168 Views

In this chapter we see what happens when we update the values in a tuple, which is actually immutable. We will be able to merge new values with old values but that throws an error. We can study the bytecode of the error and understand better how the rules for tuple work.First we define a tuple and then issue a command to update its last element as shown below.Example>>> tupl = (5, 7, 9, [1, 4]) >>> tupl[3] += [6, 8]OutputRunning the above code gives us the following result −Traceback (most recent call last): File "", line 1, in TypeError: ...

Read More

Absolute Deviation and Absolute Mean Deviation using NumPy

Pradeep Elance
Pradeep Elance
Updated on 03-Jul-2020 1K+ Views

In Statistical analysis study of data variability in a sample indicates how dispersed are the values in a given data sample. The two important ways we calculate the variability are Absolute Deviation and  Mean Absolute Deviation.Absolute DeviationIn this method we first find the mean value of the given sample and then calculate the difference between each value and the mean value of the sample called as the absolute deviation value of each data sample. So for the values higher than mean the value the deviation value will be positive and for those lower than the mean value the deviation value ...

Read More

Absolute and Relative frequency in Pandas

Pradeep Elance
Pradeep Elance
Updated on 03-Jul-2020 902 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
Showing 7881–7890 of 8,519 articles
« Prev 1 787 788 789 790 791 852 Next »
Advertisements