Focus mode
tuple
veri tipi listeler gibi birden çok veri tipini bir arada tutmamızı sağlar.tuple
'lar immutable
dır.x
ve y
koordinat değerleri var (x,y). Deniz fenerini söküp götüremiyoruz, ben bu iki değerin sabit, değiştirilemez olmasını istiyorum. Burada bu iki değeri tutmak için tuple
kullanmam mantıklı olabilir. tuple
'lar (element1,element2...)
şeklinde tanımlanır.tuple
'lar listeler gibi farklı veri yapılarında elemanlardan oluşabilir. Elemanları tuple
bile olabilir.x = 10
y = 34
konum = (10, 34)
konum[0]
10
konum[:]
(10, 34)
konum[0] = 100
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-62043221042e> in <module>
----> 1 konum[0] = 100
TypeError: 'tuple' object does not support item assignment
t = (1,2,3,"a")
t
(1, 2, 3, 'a')
t = ((1,2),3)
t
t[0]
(1, 2)
t[1]
3
t = ([1,2,3],2,(1,2))
t
([1, 2, 3], 2, (1, 2))
t[0][0] = 23
t
([23, 2, 3], 2, (1, 2))
l = [[1,2,3], [10,20]]
l
[[1, 2, 3], [10, 20]]
x = 2
y = 3
temp = x
x = y
y = temp
x
3
y
2
x = 2
y = 3
(x, y) = (y, x)
x
3
y
2
tuple
olarak görüyor.1,2,3,4
(1, 2, 3, 4)
a = 1,2,3,4
a
(1, 2, 3, 4)
type(a)
tuple
x = 2
y = 3
x, y = y, x
x
3
y
2
x = 2
y = 3
[x, y] = [y, x]
x
3
y
2
You need to enroll in the course to be able to comment!