Found 10784 Articles for Python

Writing files in background in Python

Samual Sam
Updated on 30-Jul-2019 22:30:24

140 Views

Here we are trying to do two tasks at a time, one in the foreground and the other in the background. We’ll write something in the file in the background and of a user input number, will find if it’s an odd or even number.Doing multiple tasks in one program in python is possible through multithreading in Live Demoimport threading import time class AsyncWrite(threading.Thread):    def __init__(self, text, out):       threading.Thread.__init__(self)       self.text = text       self.out = out    def run(self):       f = open(self.out, "a")       f.write(self.text + '') ... Read More

Difference between Method and Function in Python

karthikeya Boyini
Updated on 26-Aug-2023 08:56:37

28K+ Views

FunctionA function is a block of code to carry out a specific task, will contain its own scope and is called by name. All functions may contain zero(no) arguments or more than one arguments. On exit, a function can or can not return one or more values.Basic function syntaxdef functionName( arg1, arg2, ...):    ...    # Function_body    ...Let's create our own (user), a very simple function called sum (user can give any name he wants). Function "sum" is having two arguments called num1 and num2 and will return the sum of the arguments passed to the function(sum). When ... Read More

Python program to print duplicates from a list of integers?

AmitDiwan
Updated on 11-Aug-2022 11:41:43

2K+ Views

We will display duplicates from a list of integers in this article. The list is can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that the items in a list need not be of the same type Let’s say we have the following input list − [5, 10, 15, 10, 20, 25, 30, 20, 40] The output display duplicate elements − [10, 20] Print duplicates from a list of integers using for loop We will display the duplicates of a list of integer using a for loop. We ... Read More

Python program to print all the numbers divisible by 3 and 5 for a given number

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

18K+ Views

This is a python program to print all the numbers which are divisible by 3 and 5 from a given interger N. There are numerous ways we can write this program except that we need to check if the number is fully divisble by both 3 and 5.Below is my code to write a python program to print all the numbers divisible by 3 and 5 −lower = int(input("Enter lower range limit:")) upper = int(input("Enter upper range limit:")) for i in range(lower, upper+1):    if((i%3==0) & (i%5==0)):       print(i)OutputEnter lower range limit:0 Enter upper range limit:99 0 15 ... Read More

Difference between Python iterable and iterator

AmitDiwan
Updated on 12-Aug-2022 12:48:42

554 Views

What is an iterable? An iterable can be loosely defined as an object which would generate an iterator when passed to inbuilt method iter(). There are a couple of conditions, for an object to be iterable, the object of the class needs to define two instance method: __len__ and __getitem__. An object which fulfills these conditions when passed to method iter() would generate an iterator. Iterators Iterators are defined as an object that counts iteration via an internal state variable. The variable, in this case, is NOT set to zero when the iteration crosses the last item, instead, StopIteration() is ... Read More

Implementation of Dynamic Array in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

12K+ Views

Dynamic ArrayIn python, a list, set and dictionary are mutable objects. While number, string, and tuple are immutable objects. Mutable objects mean that we add/delete items from the list, set or dictionary however, that is not true in case of immutable objects like tuple or strings.In python, a list is a dynamic array. Let's try to create a dynamic list −>>> #Create an empty list, named list1 >>> list1 = [] >>> type (list1) Add some items onto our empty list, list1 −>>> # Add items >>> list1 =[2, 4, 6] >>> list1 [2, 4, 6] >>> # Another way ... Read More

Geographical plotting using Python plotly

Samual Sam
Updated on 30-Jul-2019 22:30:24

292 Views

Python provides various libraries to handle geographical and graph data. Python plotly is one of those libraries which are used to draw geographical graphs. Plotly is a free and open source library. Plotly helps to plot various kinds of graphs like Line charts, Horizontal bar charts, bar charts, dashboards, scatter plots, bubble charts, pie charts and many more.# Import important python geographical libraries. import plotly.plotly as py import plotly.graph_objs as go import pandas as pd # Must enable in order to use plotly off-line. from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot # To establish connection init_notebook_mode() # type defined is ... Read More

Exploratory Data Analysis in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

2K+ Views

For data analysis, Exploratory Data Analysis (EDA) must be your first step. Exploratory Data Analysis helps us to −To give insight into a data set.Understand the underlying structure.Extract important parameters and relationships that hold between them.Test underlying assumptions.Understanding EDA using sample Data setTo understand EDA using python, we can take the sample data either directly from any website or from your local disk. I’m taking the sample data from the UCI Machine Learning Repository which is publicly available of a red variant of Wine Quality data set and try to grab much insight into the data set using EDA.import pandas ... Read More

Add packages to Anaconda environment in Python

Samual Sam
Updated on 31-Oct-2023 03:51:13

20K+ Views

There are multiple ways by which we can add packages to our existing anaconda environment.Method 1 − One common approach is to use the “Anaconda Navigator” to add packages to our anaconda environment. Once “Ananconda Navigator” is opened, home page will look something like −Go to Environments tab just below the Home tab and from there we can check what all packages are installed and what is not.It is very easy to install any package through anaconda navigator, simply search the required package, select package and click on apply to install it. Let's suppose tensorflow packages are not installed in ... Read More

Plotting Google Map using gmplot package in Python?

karthikeya Boyini
Updated on 30-Jun-2020 09:05:26

3K+ Views

There are numerous ways you can draw geographical coordinates on Google Maps. However, in case you want to save it in a local file, one better way to accomplish is through a python module called gmplot.Python library gmplot allows us to plot data on google maps. gmplot has a matplotlib-like interface to generate the HTML and javascript to deliver all the additional data on top of Google Maps.InstallationIt is easy to install gmplot using pip incase gmplot is not already installed −pip install gmplotOn running above command, you may see output something like −From above, we can see the latest ... Read More

Advertisements