Python 1 Mod 3 Unit 3.2 - Tuples

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What does it mean that a tuple is "immutable"?

It cannot be changed after it is defined.

Statement to convert a tuple into a list

L = list(T)

Syntax to create an empty tuple

T = ()

Syntax to create a tuple

T = (val, val, val...)

Syntax to create a tuple with 1 item

T = (val,)

Code to concatenate two tuples

T = T1 + T2

Statement to convert a list into a tuple

T = tuple(L)

Statement to create a subset Tuple given T = (1,2,3,4,5)

T2 = T(0:2)

Statement to access the last item in any tuple

T[-1]

Statement to access the first item in the tuple T = (13, 5, 92)

T[0]

Statement to access the second item in the tuple T = (13, 5, 92)

T[1]

What happens if you try to change the value of an item in a tuple?

TypeError exception

Statement to delete a tuple T

del(T)

Code to test whether two tuples contain equal elements

if (T1 == T2):

Code to test whether two tuples are identical

if (T1 is T2):

Code to get the number of elements in a tuple, T

len(T)

Process to assign a tuple's values to multiple variables at the same time

unpacking


Set pelajaran terkait

Unit 6: Personal Lines: Automobile Insurance

View Set

AP US History Semester 1 Final Ch 15-17

View Set

THE INTERNATIONAL SCENE OF THE 1970s

View Set

Health: Unit 4, Assignment 20 (Quiz) (unchecked)

View Set