Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python OPERATORS, Data Types: LIST, SET, TUPLE, DICTIONARY

# Create a new Python file with the name 'lab8_YourName' and Save it.


# 1. Create a list, assign 5 different values and display it using the print command

sesame_street_characters = []
sesame_street_characters = ['Elmo', 'Big Bird', 'Oscar', 'Cookie Monster', 'Grover']
print('My Most favourite characters of sesame street', sesame_street_characters)

# 2. Add a new value to the end of the list and display it using the print command


sesame_street_characters = ['Elmo', 'Big Bird', 'Oscar', 'Cookie Monster', 'Grover', 'Kermit']
print(sesame_street_characters[5])

# 3. Remove the second value from the list and display it using the print command


sesame_street_characters = ['Elmo', 'Big Bird', 'Oscar', 'Cookie Monster', 'Grover', 'Kermit']
sesame_street_characters.pop(1)
print(sesame_street_characters)

# 4. Check the length of the list and display it using the print command

sesame_street_characters = ['Elmo', 'Big Bird', 'Oscar', 'Cookie Monster', 'Grover', 'Kermit']
print("Length of list of Sesame Street Characters is = ", len(sesame_street_characters))

# 5. Display the first item using the print command

sesame_street_characters = ['Elmo', 'Big Bird', 'Oscar', 'Cookie Monster','Grover', 'Kermit']
print (sesame_street_characters[0])


# 6. Display the last item using the print command

sesame_street_characters = ['Elmo', 'Big Bird', 'Oscar', 'Cookie Monster','Grover', 'Kermit']
print (sesame_street_characters[5])
Source by github.com #
 
PREVIOUS NEXT
Tagged: #Python #Data #DICTIONARY
ADD COMMENT
Topic
Name
3+9 =