+ 1

list1=[1,2]?

list 1 = [1,2] list 2 = list 1 list 3 = list 2 [:] a = list 2 is list 1 b = list 3 is lis 1 print (a,b) Output: True False #First off, it's a single equal sign, so why are they using boolean logic? #list 2 = list 1 so [1, 2] = [1, 2]. Okay, this checks out. #list 3 = list 2 [:]? So list three, equals list two with a slice to indicate the first number is blank (which means zero index?) to the highest second number (which would be two)? So they are unequal because [1, 2] != [0, 2]? AHHHHHHH!!!!! This one really confused me. Any help appreciated.

12th Apr 2019, 9:57 PM
tristach605
tristach605 - avatar
1 Answer
0
The is keyword returns true if not only they share the same value/object, but share the same id. list2 is a direct "copy" (don't know if it's the right word for it, a reference perhaps explains it better?) thus: a = list2 is list1 # a value is: True list2[:] returns a new list with all the items of two, not the "same list". Thus: b = list3 is list1 # b value is: False That is why output is False. I wish you success!
13th Apr 2019, 2:56 AM
Luis SepĂșlveda
Luis SepĂșlveda - avatar