Found 10805 Articles for Python

Create a stopwatch using python

Pradeep Elance
Updated on 19-Dec-2019 11:40:26

854 Views

A stopwatch is used to measure the time interval between two events usually in seconds to minutes. It has various usage like in sports or measuring the flow of heat, current etc in an industrial setup. Python can be used to creat a stopwatch by using its tkinter library.This library will have the GUI features to create a stopwatch showing the  Start, Stop and Reset  option. The key component of the program is using the lable.after()  module of tkinter.label.after(parent, ms, function = None) where parent: The object of the widget which is using this function. ms: Time in miliseconds. function: ... Read More

Count set bits using Python List comprehension

Pradeep Elance
Updated on 19-Dec-2019 11:34:21

90 Views

Set bits are the bits representing 1 in the binary form of a number. In this article we will see how to count the number of set bits in a given decimal number.#53 in binary is: 110101 The number of set bits is the number of ones. Here it is 4.In the below program we take the number and convert it to binary. As the binary conversion contains 0b as the first two characters, we remove it using string splitting technique. Then use a for loop to count each bit of the binary number if that value of the digit ... Read More

Binary list to integer in Python

Pradeep Elance
Updated on 19-Dec-2019 11:14:51

1K+ Views

We can convert a list of 0s and 1s representing a binary number to a decimal number in python using various approaches. In the below examples we use the int() method as well as bitwise left shift operator.Using int()The int() method takes in two arguments and changes the base of the input as per the below syntax.int(x, base=10) Return an integer object constructed from a number or string x.In the below example we use the int() method to take each element of the list as a string and join them to form a final string which gets converted to integer ... Read More

Difference between Python and PHP.

Mahesh Parahar
Updated on 28-Nov-2019 10:48:34

260 Views

PythonPython is a high level programming language with inbuilt big library and is used to develop standalone programs. It was developed by Guido Van Rossum and its first version was released in the year 1990.PHPPHP stands for Hypertext Preprocessor, it is server side scripting language. It was developed in 1995. It is used to create dynamic web based pages.Following are the important differences between Python and PHP.Sr. No.KeyPythonPHP1Learning CurvePython requires good effort if one learns from scratch. It is similar to C++ and Java.PHP is easy to learn if user knows html and javascript.2FrameworksPopular Python frameworks are Flask, DJango.Popular PHP ... Read More

Difference between List and Tuples in Python.

Mahesh Parahar
Updated on 28-Nov-2019 10:34:59

11K+ Views

ListList is a container to contain different types of objects and is used to iterate objects.Examplelist = ['a', 'b', 'c', 'd', 'e']TuplesTuple is also similar to list but contains immutable objects. Tuple processing is faster than List.Exampletuples = ('a', 'b', 'c', 'd', 'e')Following are the important differences between List and Tuple.Sr. No.KeyListTuple1TypeList is mutable.Tuple is immutable.2IterationList iteration is slower and is time consuming.Tuple iteration is faster.3Appropriate forList is useful for insertion and deletion operations.Tuple is useful for readonly operations like accessing elements.4Memory ConsumptionList consumes more memory.Tuples consumes less memory.5MethodsList provides many in-built methods.Tuples have less in-built methods.6Error proneList operations are ... Read More

Difference Between Go and Python Programming Language

Kiran Kumar Panigrahi
Updated on 28-Jul-2022 12:34:26

251 Views

Python debuted in 1991. Google released Golang in 2012. Google's programmers built Golang to expedite development and improve other languages. Golang has stricter grammar and layout than Python.Golang allows multitasking, use of channels, goroutines, etc. Golang can be used in networking, cloud, and server-side projects. Golang can automate DevOps and site reliability. Microcontrollers, games, and robots are programmed in Golang. Golang powers Kubernetes, Prometheus, and Docker.Python is an object oriented programming language designed by Guido van Rossum in 1991 and is maintained by Python Software Foundation. Python was developed to keep language readability easy and to quickly integrate with other ... Read More

Find the version of the Pandas and its dependencies in Python

Arnab Chakraborty
Updated on 04-Nov-2019 10:09:29

137 Views

Pandas is the important package for data analysis in Python. There are different versions available for Pandas. Due to some version mismatch, it may create some problems. So we need to find the version numbers of the Pandas. We can see them easily using the following code.We can use the command like below, to get the version −pandas.__version__Example>>> import pandas as pd >>> print(pd.__version__) 0.25.2 >>>We can also get the version of the dependencies using the function like below −pandas.show_versions() >>> pd.show_versions() INSTALLED VERSIONS ------------------ commit : None python : 3.7.1.final.0 python-bits : 64 OS : Windows OS-release : 7 ... Read More

Anagram Substring Search using Python

Hafeezul Kareem
Updated on 04-Nov-2019 07:41:41

151 Views

In this tutorial, we are going to write a program which searches for all the anagram from a string.See some examples.Input: anagram = "cat" string = "tacghactcat" Output: Anagram at 0 Anagram at 5 Anagram at 7 Anagram at 8Let's see how to write the code. Follow the below steps to write code.Algorithm1. Initialize two strings. 2. Create a function which returns whether two strings are anagram to each other or not. 3. Iterate through the main string in which we have to search for the anagrams.    3.1. Check whether substring is an anagram or not using the function ... Read More

Adding a new column to existing DataFrame in Pandas in Python

Hafeezul Kareem
Updated on 26-Aug-2023 08:39:59

29K+ Views

In this tutorial, we are going to learn how to add a new column to the existing DataFrame in pandas. We can have different methods to add a new column. Let's all of them.Using ListWe can add a new column using the list. Follow the steps to add a new column.Algorithm1. Create DataFrame using a dictionary. 2. Create a list containing new column data. Make sure that the length of the list matches the length of the data which is already present in the data frame. 3. Add the list to the DataFrame like dictionary element.Let's see one example.Example# importing ... Read More

Anagram checking in Python program using collections.Counter()

Hafeezul Kareem
Updated on 04-Nov-2019 07:22:52

71 Views

Two strings are said to be anagrams of each if they have same characters even in different order. In this tutorial, we are going to check for anagram in Python using the collections.Counter() method.Input: string_one = "cat" string_two = "tac" Ouput: Truecollections.Counter()collection.Counter() returns a dictionary which contains frerquency of each character from the string. Counter object have different methods to find most common elements, unique elements, count, etc.., Let's see one example.Example# importing the collections module import collections # creating Counter object counter = collections.Counter("Hafeez") # printing the counter print(counter) # displaying most common character from the string print("Most common ... Read More

Advertisements