The analogue for strings holds true:
string1 = 'abc'
''.join(string1) == string1 # True
So why doesn’t this hold true:
list1 = ['a', 'b', 'c']
[].extend(list1) == list1 # AttributeError: 'NoneType' object has no attribute 'extend'
type([]) returns list. Why would it get perceived as a NoneType instead of a list which would have the extend method?
This is an academic question. I wouldn’t do this is regular code, I just want to understand.
Because
list.extend()modifies the list in place and does not return the list itself. What you’d need to do to get what you expect is:The functions you reference are not really analogous.
join()returns a new string created by concatenating the members of an iterator together with the string beingjoined on. An analogouslistoperation would look more like: