Focus mode
x=4
y=7
ile aynı
x, y = (4, 7)
x
4
y
7
x, y, z = (4, 7, 11)
print(x, y ,z)
4 7 11
_
diyebiliriz.x, _ = (4, 7)
x, y, z = (4, 7, 11, 4, 21)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-67-483af8373571> in <module>
----> 1 x, y, z = (4, 7, 11, 4, 21)
ValueError: too many values to unpack (expected 3)
*
yapısını kullanacağız. Aşağıdaki kod şu demek oluyor: İlk iki elemanı x ve y'ye eşitle, sonuna kadar kalan diğer tüm elemanları z'ye eşitle
. Bunun sonunda z 11,2,21'den oluşacak, tipi list olacak.x, y, *z = (4, 7, 11, 4, 21)
x
4
y
7
z
[11, 4, 21]
type(z)
list
x, y, *_ = (4, 7, 11, 12, 13)
x
4
y
7
x, y, *z, t = (4, 7, 11, 4, 21)
x
4
y
7
z
[11, 4]
t
21
x, y, *z, t, u = (4, 7, 11, 4, 21, 32, 2)
z
[11, 4, 21]
t
32
u
2
# It will give an error
x, *y, *t = (4, 7, 11, 4)
File "<ipython-input-96-d7caec8953ac>", line 5
SyntaxError: two starred expressions in assignment
Programs to Accelerate Your Progress in a Software Career
Join our 4-8 month intensive Patika+ bootcamps, start with the fundamentals and gain comprehensive knowledge to kickstart your software career!
You need to enroll in the course to be able to comment!