Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

3. Demonstrate use of List

 list1 = [10, 21, 4, 45, 66, 93]

for num in list1:

if num % 2 == 0:

print(num, end=" ")

#Create an output list which contains squares of all the numbers from 1 to 9.

l = []

for i in range(1, 10):

l.append(i * i)

print("\n\nList with square of integers from 1 to 9:")

print(l)

#Create an output list which extracts all the numbers from an input string

str = "Python4ptes10"

print("\nOriginal String : " + str)

num = ""

for c in str:

if c.isdigit():

num = num + c + " "

print("Extracted numbers from the list : " + num)

Post a Comment

0 Comments