Daily Python Puzzle: List Basics Append

What is the output of this code snippet?

 

cubes = [1, 8, 27]
cubes.append(4 ** 3)
print(cubes)

 

This puzzle shows how you can add a new value to the end of the list using the append() function. Before appending, the Python interpreter evaluates the expression given within the brackets. Recap that the ‘**’ operator returns the power function, i.e., 4 ** 3 reads four to the power of three.

 


Are you a master coder?
Test your skills now!

 

Related Video

Solution

[1,8,27,64]

 

Leave a Comment

Your email address will not be published. Required fields are marked *