Python - How to print python list elements?

Published May 13, 2021

In this python programming example we will learn how to print list elements, print Nth index element, list range elements, add two list elements. We have default python list properties to do all these list operations.

Syntax:

    print (list)              # printing complete list
    print (list[i])           # printing ith element of list
    print (list[i], list[j])    # printing ith and jth elements
    print (list[i:j])         # printing elements from ith index to Nth index
    print (list[i:])          # printing all elements from ith index
    print (list * 2)          # printing list two times
    print (listOne + listTwo)     # printing concatenated listOne & listTwo

 

Print List items in Python Example

 

listInt = [1, 24, 92, 221, 212, 137]
list2 = [100, 200, "Hello", "World"]

print (listInt)                  
print (listInt[0])               
print (listInt[0], listInt[1])    
print (listInt[2:5])             
print (listInt[1:])              
print (list2 * 2)          
print (listInt + list2)

 

Explanation: In the above example we have two lists listInt and list2.

To print list elements we will print (listInt) method

To print Nth index elements will use print (listInt[0]) method, we will pass index number to the list method

 

Output for above example

[1, 24, 92, 221, 212, 137]
1
1 24
[92, 221, 212]
[24, 92, 221, 212, 137]
[100, 200, 'Hello', 'World', 100, 200, 'Hello', 'World']
[1, 24, 92, 221, 212, 137, 100, 200, 'Hello', 'World']

 

Related

Python remove last character from string

Python convert List to String

 

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

318 Views