Skip to content

Commit c84aa08

Browse files
Done!
1 parent e5293bd commit c84aa08

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎listLengthWays.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Python code to demonstrate
2+
# length of list
3+
# using naive method
4+
5+
# Initializing list
6+
test_list = [1, 4, 5, 7, 8]
7+
8+
# Printing test_list
9+
print("The list is : " + str(test_list))
10+
11+
# Finding length of list
12+
# using loop
13+
# Initializing counter
14+
counter = 0
15+
for i in test_list:
16+
17+
# incrementing counter
18+
counter = counter + 1
19+
20+
# Printing length of list
21+
print("Length of list using naive method is : " + str(counter))
22+
23+
24+
a = []
25+
a.append("Hello")
26+
a.append("Geeks")
27+
a.append("For")
28+
a.append("Geeks")
29+
print("The length of list is: ", len(a))
30+
31+
32+
n = len([10, 20, 30])
33+
print("The length of list is: ", n)

0 commit comments

Comments
 (0)