Found 10400 Articles for Python

Type Conversion in Python

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

1K+ Views

Using Python, we can easily convert data into different types. There are different functions for Type Conversion. We can convert string type objects to numeric values, perform conversion between different container types etc. In this section we will see how the conversions can be done using Python. Converting String to Numeric Types To convert from String type objects to Numeric Objects, there are different methods like int(), float() etc. Using the int() method we can convert any number as string to integer value (base 10). It takes the string type argument, default base is 10, We can also specify the ... Read More

Merge two sorted arrays in Python using heapq?

Samual Sam
Updated on 26-Jun-2020 12:19:06

508 Views

In this section we will see how two sorted lists can be merged using the heapq module in Python. As an example, if list1 = [10, 20, 30, 40] and list2 = [100, 200, 300, 400, 500], then after merging it will return list3 = [10, 20, 30, 40, 100, 200, 300, 400, 500]To perform this task, we will use the heapq module. This module comes with Python as Standard Library Module. So we need to import it before using it.import heapqThe heapq module has some properties. These are like below −Method heapq.heapify(iterable)It is used to convert an iterable dataset ... Read More

Creating child process using fork() in Python

karthikeya Boyini
Updated on 26-Jun-2020 12:19:41

2K+ Views

Our task is to create a child process and display process id of both parent and child process using fork() function in Python.When we use fork(), it creates a copy of itself, it is a very important aspect of LINUX, UNIX. fork() is mainly applicable for multithreading environment that means the execution of the thread is duplicated created a child thread from a parent thread. When there is an error, the method will return a negative value and for the child process, it returns 0, Otherwise, it returns positive value that means we are in the parent process.The fork() module ... Read More

Turtle programming in Python

karthikeya Boyini
Updated on 27-Aug-2023 03:38:10

57K+ Views

Turtle is a special feature of Python. Using Turtle, we can easily draw in a drawing board.First, we import the turtle module. Then create a window, we create a turtle object, and using the turtle() method we can draw on the drawing board. Some turtle method METHOD PARAMETER DESCRIPTION Turtle() None It creates and returns a new turtle object forward() amount It moves the turtle forward by the specified amount backward() amount It moves the turtle backward by the specified amount right() angle It turns the turtle clockwise ... Read More

Play a video in reverse mode using Python OpenCv

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

666 Views

The full form of OpenCv is Open Source Computer Vision, using this library we can perform different operations on images, videos.Application areas of OpenCVFacial recognition systemMotion trackingArtificial neural networkDeep neural networkVideo streaming etc.For installing on Windows we can use this command linepip install opencv-pythonFor Linux −sudo apt-get install python-opencvTo complete our task we have to follow some steps −Step 1: We import OpenCv library named cv2. Step 2: Take a video as input data. Step 3: First we break the video into a number of frames and store all these frames in a list. Step 4: When we are getting ... Read More

Read and Write to an excel file using Python openpyxl module

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

6K+ Views

Python provides openpyxl module for operating with Excel files. How to create Excel files, how to write, read etc. can be implemented by this module. For installing openpyxl module, we can write this command in command prompt pip install openpyxl If we want to give a sheet title name Example code import openpyxl my_wb = openpyxl.Workbook() my_sheet = my_wb.active my_sheet_title = my_sheet.title print("My sheet title: " + my_sheet_title) Output My sheet title:Sheet To change Title Name Example code import openpyxl my_wb = openpyxl.Workbook() my_sheet = my_wb.active my_sheet.title = "My New Sheet" print("sheet name ... Read More

Python Tools for Web scraping

Samual Sam
Updated on 26-Jun-2020 09:29:53

317 Views

In computer science Web scraping means extracting data from websites. Using this technique transform the unstructured data on the web into structured data.Most common web Scraping tools In Python3 are −Urllib2RequestsBeautifulSoupLxmlSeleniumMechanicalSoupUrllib2 − This tool is pre-installed with Python. This module is used for extracting the URL's. Using urlopen () function fetching the URL's using different protocols (FTP, HTTPetc.).Example codefrom urllib.request import urlopen my_html = urlopen("https://www.tutorialspoint.com/") print(my_html.read())Outputb'\r \r

Generating random strings until a given string is generated using Python

Samual Sam
Updated on 26-Jun-2020 09:33:53

565 Views

Given a string, our task is to generate some strings using the random combination of characters, special characters, numbers etc.ExampleInput PP Output AK AK . . . . .AlgorithmStep 1: Input a string. Step2: Here we store all possible combination of lowercase, uppercase and special characters in a variable. Step3: Use two loops and use random function. From this, we can get all the possible combinations of characters, symbols. Step4: At the end display same string which is same as an input string and it matches each random string with given input string. Step5: If both index values are same ... Read More

A single neuron neural network in Python

karthikeya Boyini
Updated on 26-Jun-2020 09:35:04

776 Views

Neural networks are very important core of deep learning; it has many practical applications in many different areas. Now a days these networks are used for image classification, speech recognition, object detection etc.Let’s do understand what is this and how does it work?This network has different components. They are as follows −An input layer, xAn arbitrary amount of hidden layersAn output layer, ŷA set of weights and biases between each layer which is defined by W and bNext is a choice of activation function for each hidden layer, σ.In this diagram 2-layer Neural Network is presented (the input layer is ... Read More

Decimal Functions in Python

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

13K+ Views

In Python, there is a module called Decimal, which is used to do some decimal floating point related tasks. This module provides correctly-rounded floating point arithmetic. To use it at first we need to import it the Decimal standard library module. import decimal In this section we will see some important functions of the Decimal module. The square root function sqrt() and Exponent function exp() The sqrt() method is used to calculate the square root of a given decimal type object. And the exp() method returns the e^x value for the given x as Decimal number. Example Code ... Read More

Advertisements