Using clear()
method
Check if element exists in list in Python
Demonstrating to check the existence of an element in the list using the Naive method and in .
[mai mult...]How to find largest element in an array with python
Input : arr[] = {10, 20, 4} Output : 20 Input : arr[] = {20, 10, 20, 4, 100} Output : 100[mai mult...]
How to find sum of array with python
def
_sum(arr):
# initialize a variable
# to store the sum
# while iterating through
# the array later
sum
=
0
# iterate through the array
# and add each element to the sum variable
# one at a time
for
i
in
arr:
sum
=
sum
+
i
return
(
sum
)
# driver function
arr
=
[]
# input values to list
arr
=
[
12
,
3
,
4
,
15
]
# calculating length of array
n
=
len
(arr)
ans
=
_sum(arr)
# display sum
print
(
'Sum of the array is '
, ans)
Output:
[mai mult...]
Sum of the array is 34
Print negative numbers in a list with Python
Example:
Input: list1 = [12, -7, 5, 64, -14] Output: -7, -14 Input: list2 = [12, 14, -95, 3] Output: -95[mai mult...]
Print positive numbers in a list with python
Example: Input: list1 = [12, -7, 5, 64, -14] Output: 12, 5, 64 Input: list2 = [12, 14, -95, 3] Output: [12, 14, 3][mai mult...]
Multiply all numbers in the list with python
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=6 Input : list1 = [3, 2, 4] Output : 24[mai mult...]
Python program to find smallest number in a list
Given a list of numbers, the task is to write a Python program to find the smallest number in given list.
Examples:
Input : list1 = [10, 20, 4] Output : 4 Input : list2 = [20, 10, 20, 1, 100] Output : 1[mai mult...]
How to print all Prime numbers in an Interval with Python
Given two positive integers start and end. The task is to write a Python program to print all Prime numbers in an Interval.
Definition: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first few prime numbers are {2, 3, 5, 7, 11, ….}.
[mai mult...]Python Program for Program to find area of a circle
Area of a circle can simply be evaluated using following formula.
Area = pi * r2 where r is radius of circle[mai mult...]