Python: Display the first and last colors from a given list
First and Last Colors
Write a Python program to display the first and last colors from the following list.
color_list = ["Red","Green","White" ,"Black"]
Pictorial Presentation:

Sample Solution:
Python Code:
# Create a list called 'color_list' containing color names
color_list = ["Red", "Green", "White", "Black"]
# Print the first and last elements of the 'color_list' using string formatting
# The '%s' placeholders are filled with the values of 'color_list[0]' (Red) and 'color_list[-1]' (Black)
print("%s %s" % (color_list[0], color_list[-1]))
Sample Output:
Red Black
Explanation:
The said code creates a list named "color_list" which includes four different colors, "Red", "Green", "White", and "Black". Then, it utilizes string formatting to print the first (Index 0) and the last (Index -1) color of the list together with a space in between. The output would be "Red Black".
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program that prints the second and second-last colors from a given list.
- Write a Python script that takes a list of colors and prints them in reverse order.
- Write a Python program that takes a list of colors and finds the longest color name.
- Write a script to check if a specific color exists in the given list.
Go to:
Previous: Write a Python program to accept a filename from the user and print the extension of that.
Next: Write a Python program to display the examination schedule. (extract the date from exam_st_date).
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.