Tag: Numbers
Get sum of numbers in a list
In this article, we will discuss different ways to get the sum of all numbers in a list in Python. Table Of Contents Method 1: Using sum() function Method 2: Using for loop Method 3: Using Generator expression Summary Method 1: Using sum() function Python provides a function sum(). It accepts a sequence as argument, …
Extract even numbers from a list in Python
In this article, we will discuss different ways to select even numbers from a list in Python. Table Of Contents Introduction Method 1: Using List Comprehension Method 2: Using List Comprehension & AND operator Method 3: Using For Loop Summary Introduction Suppose we have a list, that contains only numbers. Like this, Advertisements [10, 11, …
Extract Odd numbers from a List in Python
In this article, we will discuss different ways to select odd numbers from a list in Python. Table Of Contents Introduction Method 1: Using List Comprehension Method 2: Using List Comprehension & AND operator Method 3: Using For Loop Summary Introduction Suppose we have a list, that contains only numbers. Like this, Advertisements [10, 11, …
Create a List of numbers from 1 to N in Python
In this article, we will discuss how to create a Python List of numbers from 1 to N. Table Of Contents Introduction Method 1: Using range() function Example 1: With step size 1 Example 2: With step size 2 Method 2: Using numpy.arange() function Example 1: With step size 1 Example 2: With step size …
Create a List with numbers between two values in Python
In this article, we will discuss how to create a Python List of numbers between two values. Table Of Contents Introduction Method 1: Using range() function Method 2: Using numpy.arange() function Method 3: Using while loop Method 4: Using List Comprehension Summary Introduction Suppose first value is 20, and second value is 30, and we …
Create a List with numbers between two values in PythonRead More
Convert all positive numbers in a List to negative in Python
In this article, we will discuss different ways to convert all positive numbers in a List to negative numbers in Python. Table Of Contents Method 1: Using List Comprehension and if-else Method 2: Using map() function Method 3: Using for-loop Method 4: Using NumPy Summary Method 1: Using List Comprehension and if-else Inside a List …
Convert all positive numbers in a List to negative in PythonRead More
Print a specific range of numbers in Python
In this article, we will discuss different ways to print a specific range of numbers in Python. Table Of Contents Introduction Method 1: Using range() function Method 2: Using List Comprehension Method 3: Using while loop Summary Introduction Suppose we want to print numbers between two specific numbers like 5 & 15. It should print …
Pandas: Add Column with serial numbers in DataFrame
In this article, we will discuss different ways to add a new column in DataFrame containing serial numbers like, CS-001 CS-002 CS-003 CS-004 CS-005 CS-006 Table Of Contents Preparing DataSet Add new column with Serial values in Pandas DataFrame Add new column with Serial values in Pandas using List comprehension Summary Preparing DataSet First we …
Pandas: Add Column with serial numbers in DataFrameRead More
Convert all positive numbers to negative in Python List
This tutorial will discuss about unique ways to convert all positive numbers to negative in Python list. Table Of Contents Using List Comprehension Using map() function Using NumPy Array Summary Using List Comprehension Iterate over all numbers in Python List using a List comprehension. During iteration, for each number check if it is greater than …
Convert all positive numbers to negative in Python ListRead More
Check if All Numbers in Array are Less than a Number in C++
This tutorial will discuss about a unique way to check if all numbers in array are less than a number in C++. To check if all the elements of an array are less than a given number, we need to iterate over all the elements of array and check each element one by one. For …
Check if All Numbers in Array are Less than a Number in C++Read More