-1

I am trying to do extended unpacking of tuple with * syntax. I'm trying to format string with f'' string syntax. None of those work in visual-studio-code python3.7.3 linuxmint64 system.

l = [1, 2, 3, 4, 5, 6]

a, *b = l
print(a, b)

Here is the error :

line 3

    a, *b = l
       ^
SyntaxError: invalid syntax
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56

1 Answers1

0

Your Code:

l = [1, 2, 3, 4, 5, 6]

a, *b = l
print(a, b)

The above code won't as the correct syntax is b=[*l]. The * is used to unpack a list. So if you want to have some values in both a and b so the code below...

l = [1, 2, 3, 4, 5, 6]
d = [3,2,1]
a , b = [*l] , [*d]  # Here [*l] unpacks l in a list and assign it to a and
                     # and [*d] unpacks d in a list and assign it to b 

print(a , b)

Hope this helps...

Chetan Vashisth
  • 438
  • 4
  • 14