Basics of Python-4

Photo by Chris Ried on Unsplash

Basics of Python-4

Day 4

List :

Previously I have discussed that,

A list is a sequential data type

  1. An ordered collection of data

  2. It is mutable.

  3. It's an abstract data type.

Let's solve a few problems on the list :

  1. Write a python program to reverse a list
l=[34,76,23,11]
print(l[::-1])

output:

this is the easiest way to solve the reverse list by using the slicing operator.

  1. Write a python program to find out the length of the list
l=[3,6,3,4]
print(len(l))

output :

These are the basic code that I have solved by listing, using keywords.

  1. Write a Python program to print all negative numbers in a range.
n=int(input("enter the first number"))
m=int(input("enter the second number"))
print([i for i in range(n,m+1) if i<0])

Output:

Here are some basic questions on the list:

QUESTIONS
Write a python program to swap elements in the string list
Write a python program to find the length of the list
Write a python program to find a maximum of two numbers in Python
Write a python program to find a minimum of two numbers in Python
Write a python program to check if an element exists in the list
Write a python program to clear a list in Python
Write a python program to reverse a list
Write a python program to clone or Copying a list
Write a python program to count occurrences of an element in a list
Write a Python Program to find the sum and average of the list in Python

In my next blogs, you will get to know about loops and their uses.

Thank you.