Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python program to find largest number in a list

Python program to find the largest number in a list Given a list of numbers, the task is to write a Python program to find the largest number in given list. Examples: Input : list1 = [10, 20, 4] Output : 20 Input : list2 = [20, 10, 20, 4, 100] Output : 100 Method…
Read more

Python program to find smallest number in a list

Python program to find the smallest number in a list Given a list of numbers, the task is to write a Python program to find the smallest number in the given list. Examples: Input : list1 = [10, 20, 4] Output : 4 Input : list2 = [20, 10, 20, 1, 100] Output : 1…
Read more

Python | Multiply all numbers in the list (3 different ways)

Python | Multiply all numbers in the list (3 different ways) Given a list, print the value obtained after multiplying all numbers in a list. Examples: Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=6 Input : list1 = [3, 2, 4] Output : 24   Method 1: Traversal Initialize the value…
Read more

Python program to find sum of elements in list

Python program to find sum of elements in list Given a list of numbers, write a Python program to find the sum of all the elements in the list. Example: Input: [12, 15, 3, 10] Output: 40 Input: [17, 5, 3, 5] Output: 33 Example #1: # Python program to find sum of elements in…
Read more

Python | Count occurrences of an element in a list

Python | Count occurrences of an element in a list Given a list in Python and a number x, count number of occurrences of x in the given list. Examples: Input : lst = [15, 6, 7, 10, 12, 20, 10, 28, 10] x = 10 Output : 3 10 appears three times in given…
Read more

Python | Cloning or Copying a list

Python | Cloning or Copying a list In this article we will go through various ways of copying or cloning a list in Python. These various ways of copying takes different execution time, so we can compare them on the basis of time. Using slicing technique This is the easiest and the fastest way to…
Read more

Python | Reversing a List

Python | Reversing a List Python provides us with various ways of reversing a list. We will go through few of the many techniques on how a list in python can be reversed. Examples: Input : list = [10, 11, 12, 13, 14, 15] Output : [15, 14, 13, 12, 11, 10] Input : list…
Read more

Different ways to clear a list in Python

Different ways to clear a list in Python There are many ways of clearing the list through methods of different constructs offered by Python language. Let’s try to understand each of the method one by one. Method #1 : Using clear() method # Python program to clear a list # using clear() method # list…
Read more

Python | Ways to check if element exists in list

Python | Ways to check if element exists in list List is an important container in python as if stores elements of all the datatypes as a collection. Knowledge of certain list operations are necessary for day-day programming. This article discusses one of the basic list operation of ways to check existence of element in…
Read more

Python | Ways to find length of list

Python | Ways to find length of list List being an integral part of Python day-day programming has to be learned by all the python users and having a knowledge of its utility and operations is essential and always a plus. So this article discusses one such utility of finding the no. of elements in…
Read more