Frenk Frenk
Frenk Frenk

Reputation: 113

List Slicing in a Conditional Statement

This is the code I'm referring to the above question,

my_list = [1, 2, 3, 4, 5]

if(another_list == my_list[2:]):
   print("good")
else:
   print("bad")

In the code sample above, is my_list[2:] stored in the memory (like we assigned it to a variable)? Or is it forgotten after the conditional is over?

Upvotes: 0

Views: 204

Answers (1)

ad stefnum
ad stefnum

Reputation: 98

You didn't assign it to a variable so it isn't stored. It is forgotten after the conditional but it will always work when the program is run again if the program is more or less the same.

Upvotes: 1

Related Questions