Creating List python class 11 comprehensive notes

Creating list python class 11 provides you with detailed study material for CBSE Computer science class 11 for the topic list and how to create a list in python. So here we go!

Introduction to Creating list python class 11

As you know list python supports different types of data types like numbers, strings, and boolean values. This article Creating list python class 11 will help you to understand the concept of list and how to create different kinds of lists in python.

These values you can store in different variables. But sometimes we need a list of similar or different types of data in a single unit. Or we need something which prepares a set of similar or different values.

For example, Let’s assume a student is an object. Now a student can have roll no, name, class, date of birth etc. The details we want to use in the program all should come in a single unit. Here, a list will help to serve this purpose.

So let us start the article Creating a list python class 11 with the definition of a list.

Definition of List

A list a type of a python collection that can store and manipulate similar as well as different types data values.

  • Those who are familiar with other programming languages may familiar with Arrays.
  • Python lists are quite similar to that but the only difference is there that the array is a collection of homogeneous (similar kind) data.
  • The python list is a collection of heterogeneous (different types) data.

In the next section of Creating a list in python class-11, we are going to discuss creating a list in python.

Different ways to Creating list python class 11

Lets discuss what are the ways to Creating list python class 11. To create a list square brackets are used. It can be represented in the following forms:

  1. Empty List: [] –> Empty lists can be created when you need add values later or size is not fixed
  2. List of numeric values: [11,22,33,44,55] –> This list contains numbers as elements.
  3. List of mixed numbers: [11,22.22,33.33,44] –> This list is a collection of integers and float numbers.
  4. List of letters: [‘x’,’y’,’z’] –> This list is collection of letters or alphabets
  5. List of words: [‘Hello’,’How’,’are’,’you’] –> This list is collection few words
  6. List of mixed different data types: [‘00001′,’Sagar’,10001,’12/12/2005′] –> This list is a collection of a student record with different data values

in the next section of Creating a list python class 11, we are going to discuss creating an empty list.

Creating An Empty List – Creating list python class 11

To create an empty list declare one list and initialize it with square brackets without any value.

l = []

In the above statement, I have created an empty list named l. Now, whenever I want to access elements from this list I will use l and then manipulate the list with different expressions.

In the next section of Creating a list python class 11 I will cover the topic of creating lists with multiple values.

Creating lists with multiple values – Creating list python class 11

To create lists with multiple values initialize your list with the values you want to put in the list.

l = [22,33.33,45,'17/08/2001','Hetal','Parmar']

The list values can be accessed by its index.

IndexValue
0 – l[0]22
1 – l[1]33.33
2 – l[2]45
3 – l[3]17=/08/2001
4 – l[4]Hetal
5 – l[5]Parmar

Creating nested list – Creating list python class 11

A list can be an element of another list. This type of list is known as a nested list.

l = [1,'Manish',[56,67,89]]

The values can be accessed in the following:

l[0]=1

l[1]=Manish

l[2][0]=56

l[2][1]=67

l[2][2]=89

Creating a list from a word or text – Creating list python class 11

The text initialized with the list function returned as a list.

l = list('Python Lists')
print(l)

Output –> [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘ ‘, ‘L’, ‘i’, ‘s’, ‘t’, ‘s’]

Now in the next section of Creating a list python class 11, we will cover the topic of creating list from user input.

Creating a list from user input – Creating list python class 11

Use input function to create a list in following manner.

l = list(input("Enter a value"))
print(l)

Output –>

Enter values:4567
[‘4’, ‘5’, ‘6’, ‘7’]

Observe the output given above, when you take values from input it always returns the numbers as strings with single quotes in a list. To avoid this you can use this.

To do this use the eval function and enter values with square brackets:

l = eval(input("Enter values"))
print(l)

Output–>

Enter values: [4,5,6,7]

[4,5,6,7]

Whenever the eval function is used with the input you can enter the values in form of a list itself at the input console.

Watch this video for more understanding of the topic Creating list in python class-11:

Follow this link for more notes on lists:

List manipulations Class 11 | QnA List Manipulations
List functions Class 11 | QnA List functions

Thank you for visiting my blog and reading this article Creating list in python class-11. If you have any queries or doubts or want to share any views on this article Creating list in python class-11, feel free to write in the comment section.

Leave a Reply