Integreeritud tuple () abil saab luua Pythonis hulgi.
Pythonis on dupleks muutumatu järjestustüüp. Üks moodulite loomise viisidest on tuple()
konstruktsiooni kasutamine.
Süntaks tuple()
on:
kahekordne (korduv)
tuple () parameetrid
- iterable (valikuline) - iterable (loend, vahemik jne) või iteraatori objekt
Kui iterable ei ole edastatud tuple()
, tagastab funktsioon tühja dupleksi.
Näide: moodulite loomine tuple () abil
t1 = tuple() print('t1 =', t1) # creating a tuple from a list t2 = tuple((1, 4, 6)) print('t2 =', t2) # creating a tuple from a string t1 = tuple('Python') print('t1 =',t1) # creating a tuple from a dictionary t1 = tuple((1: 'one', 2: 'two')) print('t1 =',t1)
Väljund
t1 = () t2 = (1, 4, 6) t1 = ('P', 'y', 't', 'h', 'o', 'n') t1 = (1, 2)
Soovitatav kirjand : Python Tuples