22.8k views
5 votes
What will be printed when the following code is executed?

x = 4
x = 'Black widow'
print(x)

1 Answer

4 votes

Final answer:

The code will print 'Black widow' because the variable x is reassigned to this string value before the print function is called.

Step-by-step explanation:

When the code is executed, the following sequence of operations occurs:

  • The variable x is initially set to the integer 4.
  • Then, the variable x is reassigned to the string 'Black widow'.
  • The print() function is called to display the current value of x, which is now 'Black widow'.

So, the output printed to the screen will be: Black widow

User Awemo
by
8.3k points