Python
Tekst

Inne typy danych: tuple, zbiory

Lekcja 33 Moduł 6

Python 3.6.9 (default, Jul 17 2020, 12:50:27)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.

>>> lista_1 = [ 2, 4, 5, 4, 3.14 ]
>>> tupla_1 = ( 2, 4, 5, 4, 3.14 )

>>> type(lista_1)
<class 'list'>
>>> type(tupla_1)
<class 'tuple'>
>>> lista_1[3]
4
>>> tupla_1[3]
4
>>> lista_1[3] = 55
>>> lista_1
[2, 4, 5, 55, 3.14]

>>> tupla_1[3] = 44
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    tupla_1[3] = 44
TypeError: 'tuple' object does not support item assignment

>>> del(tupla_1[3])
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    del(tupla_1[3])
TypeError: 'tuple' object doesn't support item deletion

>>> zbior_1 = set(lista_1)
>>> type(zbior_1)
<class 'set'>
>>> zbior_1
{2, 3.14, 4, 5, 55}
>>> zbior_2 = set(tupla_1)
>>> zbior_2
{2, 3.14, 4, 5}
>>> del(zbior_1[2])
Traceback (most recent call last):
  File "<pyshell#15>", line 1, in <module>
    del(zbior_1[2])
TypeError: 'set' object doesn't support item deletion
>>>

Leave a comment

Comment as a guest:

Name E-Mail
Website
Pen