Found 33676 Articles for Programming

ldexp() function in C/C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

201 Views

Here we will see what is the use of ldexp() method in C or C++. This function returns any variable x raise to the power of exp value. This takes two arguments x and exp.The syntax is like below.float ldexp (float x, int exp) double ldexp (double x, int exp) long double ldexp (long double x, int exp) double ldexp (T x, int exp)Now let us see one example to get a better idea.Example#include #include using namespace std; int main() {    double a = 10, res;    int exp = 2;    res = ldexp(a, exp); // Finds a*(2^exp)    cout

Whatsapp using Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

724 Views

In this section we are going to create a Whatsapp chatbots, but unlike few other chatbots for twitter or facebook, whatsapp chatbots don’t run on the platform directly because of whatsapp’s policies.But there is a way to get is done, using selenium, a very smart package in python with which developer’s can automate the browser’s activity. With this we can make use of whatsapp-web through the browser.RequirementsWe need three basic things to get things done: Selenium.We can install selenium very easily using pip, just run below command on your terminal −$pip install seleniumChrome/firefox or any other webdriver.As I using chrome ... Read More

Downloading files from web using Python?

Arjun Thakur
Updated on 22-Aug-2023 00:38:16

162K+ Views

Python provides different modules like urllib, requests etc to download files from the web. I am going to use the request library of python to efficiently download files from the URLs.Let’s start a look at step by step procedure to download files using URLs using request library−1. Import moduleimport requests2. Get the link or urlurl = 'https://www.facebook.com/favicon.ico' r = requests.get(url, allow_redirects=True)3. Save the content with name.open('facebook.ico', 'wb').write(r.content)save the file as facebook.ico.Exampleimport requests url = 'https://www.facebook.com/favicon.ico' r = requests.get(url, allow_redirects=True) open('facebook.ico', 'wb').write(r.content)ResultWe can see the file is downloaded(icon) in our current working directory.But we may need to download ... Read More

Partial Functions in Python?

George John
Updated on 30-Jul-2019 22:30:26

1K+ Views

Everybody loves to write reusable code, right? Then partial function is a cool thing to learn. Partial functions allows us to derive a function with x parameters to a function with fewer parameters and constant values set for the more limited function.We can write partial functional application in python through functools library. Below is a simple example of partial function from the functools library with the add function from the operator library.>>> from functools import * >>> from operator import * >>> add(1, 2) 3 >>> add1 = partial(add, 4) >>> add1(6) 10 >>> add1(10) 14Partial is a higher order ... Read More

Changing Class Members in Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

609 Views

Python object oriented programming allows variables to be used at the class level or the instance level where variables are simply the symbols denoting value you’re using in the program. At the class level, variables are referred to as class variables whereas variables at the instance level are referred to as instance variables. Let’s understand the class variable and instance variable through a simple example −# Class Shark class Shark: animal_type= 'fish' # Class Variable def __init__(self, name, age): self.name = name self.age = age # Creating objects of Shark class obj1 = Shark("Jeeva", 54) obj2 = Shark("Roli", 45) ... Read More

Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix using Python?

AmitDiwan
Updated on 12-Aug-2022 12:29:20

554 Views

In this example, we will count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix. At first, we will create a matrix − mat = [ [-1, 3, 5, 7], [-6, -3, 1, 4], [-5, -1, -10, 12] ] Pass the matrix to a custom function and use nested for loop − def negativeFunc(mat, r, c): count = 0 for i in range(r): for j in range(c): if mat[i][j]

Logical Operators on String in Python?

Yaswanth Varma
Updated on 28-Aug-2025 13:03:49

3K+ Views

In this article, we are going to learn about the logical operators on strings in Python. The logical operators such as and, or, and not are used to combine the conditional statements and control the flow of logic. While they are commonly used with the Boolean values, they can also be used with strings and other non-Boolean types.Logical Operators on String in Python? In Python the non-empty strings are considered as true, and the Empty strings ("") are considered as false. When the logical operators are applied to the strings, they do not return Boolean values directly; instead, they return one ... Read More

Generate all permutation of a set in Python?

SaiKrishna Tavva
Updated on 17-Dec-2024 13:06:16

5K+ Views

Permutations refer to arranging the members of a set into different sequences. if the set is already ordered, rearranging (reordering) its elements. If a set has n elements, the total number of permutations is n! (factorial of n) Some common approaches we can use to generate all permutations of a set in Python are as follows. Using a for loop Using itertools.permutations() function. ... Read More

Class or Static Variables in Python?

Yaswanth Varma
Updated on 28-Aug-2025 13:08:36

6K+ Views

In this article we are going to learn about class or static variables on python. The class variables or static variables that are used to share across all the instances of a class. Unlike the instance variables which are specific to each object, Class variables maintain the common value for all the objects of the class. They are defined within the class but outside any instance methods, making them accessible to all the instances. These variables are used when we want to have a single shared state or value among all instance. Example 1 Let's look ... Read More

Division Operators in Python?

Akshitha Mote
Updated on 22-Jan-2025 13:41:32

1K+ Views

The Python division operator is used to divide two integer values and return a quotient. To perform a division operation, we use the / symbol. For example, 16 divided by 4 is written as 16 / 4, which returns 4 as the quotient. Here, 16 is known as divident and 4 is known as divisor. The division operator is one of the arithmetic operator. When we divide an integer by zero, it will raise a ZeroDivisionError exception in Python. For example, if we try to divide 55 by 0 using 55 / 0, it will raise a ZeroDivisionError exception. Types ... Read More

Advertisements