Q:

Python | Program to declare and print a list

belongs to collection: Python List Programs

0

Python | Program to declare and print a list

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Declare a list and print the elements/objects of the list in Python.

Program:

# declaring list with integer elements
list1 = [10, 20, 30, 40, 50]

# printing list1
print "List element are: ", list1


# printing elements of list1 by index
print "Element @ 0 index:", list1[0]
print "Element @ 1 index:", list1[1]
print "Element @ 2 index:", list1[2]
print "Element @ 3 index:", list1[3]
print "Element @ 4 index:", list1[4]


# declaring list with string elements
list2 = ["New Delhi", "Mumbai", "Chennai", "calcutta"]

# printing list2
print "List elements are: ", list2

#printing elements of list2 by index
print "Element @ 0 index:",list2 [0]
print "Element @ 1 index:",list2 [1]
print "Element @ 2 index:",list2 [2]
print "Element @ 3 index:",list2 [3]
print " " # prints new line

# declaring list with mixed elements
list3 = ["Amit Shukla", 21, "New Delhi", 9876543210]

#printing list3
print "List elements are: ", list3

# printing elements of list3 by index
print "Element @ 0 index (Name) :", list3[0]
print "Element @ 1 index (Age ) :", list3[1]
print "Element @ 2 index (City) :", list3[2]
print "Element @ 3 index (Mob.) :", list3[3]
print "" # prints new line

Output

    List element are:  [10, 20, 30, 40, 50]
    Element @ 0 index: 10
    Element @ 1 index: 20
    Element @ 2 index: 30
    Element @ 3 index: 40
    Element @ 4 index: 50
    List elements are:  ['New Delhi', 'Mumbai', 'Chennai', 'calcutta']
    Element @ 0 index: New Delhi
    Element @ 1 index: Mumbai
    Element @ 2 index: Chennai
    Element @ 3 index: calcutta
 
    List elements are:  ['Amit Shukla', 21, 'New Delhi', 9876543210]
    Element @ 0 index (Name) : Amit Shukla
    Element @ 1 index (Age ) : 21
    Element @ 2 index (City) : New Delhi
    Element @ 3 index (Mob.) : 9876543210

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python List Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program to print list elements in different... >>