I need to add an empty list to an existing tuple.
example:>>> ([1],[1,2]) + ([])
([1],[1,2],[])
My problem is that python seems to evaluate ([])
to []
on which i can't use the +
operator.
I tried tu开发者_高级运维ple([])
but that evaluates to ()
and nothing is added to the original tuple.
Thank you.
Use a one-element tuple:
([], )
# ^
Try
>>> ([1],[1,2])+([],)
([1], [1, 2], [])
Simply putting something in between parentheses makes it an expression. Add a comma at the end to mark it as a tuple.
Did you try
([1],[1,2]) + ([],)
tuples are immutable so you need to make a new tuple
a=([1],[1,2])
b=a+([],)
精彩评论