Repository navigation
Expand file tree
/
Copy path056-Create-List.py
More file actions
80 lines (64 loc) · 2.75 KB
/
Copy path056-Create-List.py
File metadata and controls
80 lines (64 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
===============================================================================
File Name : 56-Create-List.py
Description : Create a List in Python
Author : Shaik Mahaboob Basha
===============================================================================
Definition:
A list is a collection data type used to store multiple values in a single
variable. Lists are ordered, mutable, and allow duplicate values.
Syntax:
list_name = [value1, value2, value3]
Example:
numbers = [10, 20, 30]
"""
# -----------------------------------------------------------------------------
# Creating a list of integers.
# -----------------------------------------------------------------------------
numbers = [10, 20, 30, 40, 50]
# -----------------------------------------------------------------------------
# Displaying the complete list.
# -----------------------------------------------------------------------------
print("Integer List :", numbers)
# Output:
# Integer List : [10, 20, 30, 40, 50]
print()
# -----------------------------------------------------------------------------
# Creating a list of strings.
# -----------------------------------------------------------------------------
fruits = ["Apple", "Banana", "Mango", "Orange"]
# -----------------------------------------------------------------------------
# Displaying the complete list.
# -----------------------------------------------------------------------------
print("Fruit List :", fruits)
# Output:
# Fruit List : ['Apple', 'Banana', 'Mango', 'Orange']
print()
# -----------------------------------------------------------------------------
# Creating a mixed data type list.
# -----------------------------------------------------------------------------
student = [101, "Rahul", 92.5, True]
# -----------------------------------------------------------------------------
# Displaying the complete list.
# -----------------------------------------------------------------------------
print("Mixed List :", student)
# Output:
# Mixed List : [101, 'Rahul', 92.5, True]
print()
# -----------------------------------------------------------------------------
# Creating an empty list.
# -----------------------------------------------------------------------------
empty_list = []
# -----------------------------------------------------------------------------
# Displaying the empty list.
# -----------------------------------------------------------------------------
print("Empty List :", empty_list)
# Output:
# Empty List : []
print()
# -----------------------------------------------------------------------------
# Displaying the type of a list.
# -----------------------------------------------------------------------------
print("Type of numbers :", type(numbers))
# Output:
# Type of numbers : <class 'list'>