Found 35164 Articles for Programming

Python Boolean Operations

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

254 Views

The basic Boolean operations are and, or, not operations. The and operation − The basic syntax of and operation is: x and y. It indicates that when the x is false, then return x, otherwise returns y. The or operation −The basic syntax of or operation is: x or y. It indicates that when the x is false, then return y, otherwise returns x. The not operation − The basic syntax of and operation is: not x. It indicates that when the x is false, then it returns true, otherwise it returns false. Example Code Live ... Read More

Python Truth Value Testing

AmitDiwan
Updated on 12-Aug-2022 12:54:26

832 Views

What is Truth Value We can use any object to test the truth value. By providing the condition in the if or while statement, the checking can be done. Until a class method __bool__() returns False or __len__() method returns 0, we can consider the truth value of that object is True. The value of a constant is False, when it is False, or None. When a variable contains different values like 0, 0.0, Fraction(0, 1), Decimal(0), 0j, then it signifies the False Value. The empty sequence ‘‘, [], (), {}, set(0), range(0), Truth value of these elements are ... Read More

Python program for removing n-th character from a string?

AmitDiwan
Updated on 11-Aug-2022 10:03:48

809 Views

In this article, we will remove the nth character from a string in Python. Let’s say we have the following input string − Amitdiwan The output should be the following after removing nth character i.e. 2nd index − Amt Python program for removing n-th character from a string In this example, we will remove the nth character from a string − Example def removechar(str1, n): x = str1[ : n] y = str1[n + 1: ] return x + y # Driver Code if __name__ == '__main__': str1 = input("Enter a String =") n = int(input("Enter the ... Read More

Python program to print check board pattern of n*n using numpy

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

785 Views

Given the value of n, our task is to display the check board pattern for a n x n matrix. Different types of functions to create arrays with initial value are available in numpy . NumPy is the fundamental package for scientific computing in Python. Algorithm Step 1: input order of the matrix. Step 2: create n*n matrix using zeros((n, n), dtype=int). Step 3: fill with 1 the alternate rows and columns using the slicing technique. Step 4: print the matrix. Example Code import numpy as np def checkboardpattern(n): print("Checkerboard pattern:") ... Read More

Prefix sum array in python using accumulate function

karthikeya Boyini
Updated on 25-Jun-2020 11:31:53

354 Views

Given an array and we have to do the prefix sum array using accumulate function.itertools.accumulate(iterable[, func]) module functions all construct and return iterators. So they should only be accessed by functions or loops that truncate the stream. Make an iterator that returns accumulated sums. Elements may be any addable type including Decimal or Fraction. If the optional function argument is supplied, it should be a function of two arguments and it will be used instead of addition.ExampleInput Data = [1, 0, 2, 3, 5] >>> list(accumulate(data)) # running summation Output [1, 1, 3, 6, 11]AlgorithmStep 1: Create list. Step 2: ... Read More

Python program using map function to find row with maximum number of 1's

AmitDiwan
Updated on 11-Aug-2022 09:03:32

177 Views

In this article, we will learn how to use map function to find row with maximum number of 1's. 2D array is given and the elements of the arrays are 0 and 1. All rows are sorted. We have to find row with maximum number of 1's. Here we use map (). The map function is the simplest one among Python built-ins used for functional programming. These tools apply functions to sequences and other iterables. Let’s say the input is the following array − [[0, 1, 1, 1, 1], [0, 0, 1, 1, 1], [1, 1, 1, 1, 1], [0, ... Read More

New Features of C++17

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

347 Views

C++17 is the latest version of standard C++ language. C++11 and C++14 are the previous versions of C++. The current version makes several additions to the core language while some previous features are also removed. C++17 is known as feature full or feature complete. There are some of the new changes introduced in C++17 − Library changes - utils This is one of the most amazing feature of C++17. It merges the features and patterns of other libraries. Many of the sub-libraries are merged together into standards. The following features are added to utils library in C++17 − std::variant ... Read More

Difference between strncmp() and strcmp() in C/C++

George John
Updated on 12-Sep-2023 03:17:26

1K+ Views

strncmp()The function strncmp() is used to compare left string to right string up to a number. It works same as strcmp(). It returns a value greater than zero when the matching character of left string has greater ASCII value than the character of the right string. Returns a value less than zero when the matching character of left string has lesser ASCII value than the character of the right string.Here is the syntax of strncmp() in C language, int strncmp ( const char *leftString, const char *rightString, size_t number );Here, leftString  − The first string which is to be compared ... Read More

C++ Scope resolution operator

Chandu yadav
Updated on 25-Jun-2020 10:21:24

20K+ Views

The scope resolution operator ( :: ) is used for several reasons. For example: If the global variable name is same as local variable name, the scope resolution operator will be used to call the global variable. It is also used to define a function outside the class and used to access the static variables of class.Here an example of scope resolution operator in C++ language,Example Live Demo#include using namespace std; char a = 'm'; static int b = 50; int main() {    char a = 's';    cout

How to convert a single character to string in C++?

Arjun Thakur
Updated on 25-Jun-2020 10:09:24

133 Views

There are several methods to convert a single character to a string. In the following example, some of them are used to convert a character to a string.Here is an example of converting a single character to string in C++ language,Example Live Demo#include #include #include int main() {    char c = 'm';    std::string s(1, c);    std::cout

Advertisements