Python

4 Python List – Slicing the List

SLICING a LIST code

players = ['Vijay', 'Mohan', 'Vasu', 'Sai', 'Chandika','Shreya']
print("Here are the three players from 2ND PLAYER ONWARDS on my team:")
print(players[1:4])
players = ['Vijay', 'Mohan', 'Vasu', 'Sai', 'Chandika','Shreya']
print("Here are the FIRST THREE players on my team:")
print(players[0:3])
players = ['Vijay', 'Mohan', 'Vasu', 'Sai', 'Chandika','Shreya']
print("Here are the FIRST FOUR players on my team:")
print(players[:4])
players = ['Vijay', 'Mohan', 'Vasu', 'Sai', 'Chandika','Shreya']
print("Here are the players from SECOND PLAYER ONWARDS on my team:")
print(players[2:])
players = ['Vijay', 'Mohan', 'Vasu', 'Sai', 'Chandika','Shreya']
print("Here are the LAST three players on my team:")
print(players[-3:])

Results

Here are the three players from 2ND PLAYER ONWARDS on my team:
['Mohan', 'Vasu', 'Sai']
Here are the FIRST THREE players on my team:
['Vijay', 'Mohan', 'Vasu']
Here are the FIRST FOUR players on my team:
['Vijay', 'Mohan', 'Vasu', 'Sai']
Here are the players from SECOND PLAYER ONWARDS on my team:
['Vasu', 'Sai', 'Chandika', 'Shreya']
Here are the LAST three players on my team:
['Sai', 'Chandika', 'Shreya']

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s