08-01 Tuples

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given that t contains a tuple, write a statement that assigns the value of its first element to k.

k = t[0]

Given that t has already been defined and contains a tuple, write an expression whose value is the tuple's length.

len(t)

Given that t has been defined and contains a tuple, write a statement that assigns a list containing the same elements as t to play_list.

play_list = list(t)

Write a statement that assigns the empty tuple to t.

t = ( )

Write a statement that assigns to t a tuple that contains the following elements: 42, 56, 7.

t = (42, 56, 7)

Given that play_list has been defined and contains a list, write a statement that assigns to t a tuple containing the same elements as play_list.

t = tuple(play_list)

Write an expression that evaluates to the value of the first element contained in the tuple t.

t[0]

Given that k contains a non-negative integer value and that t has been defined and contains a tuple with at least k+1 elements, write an expression that evaluates to the kth element of t.

t[k]

Given that t has been defined and contains a tuple, write some statements that assigns to t a new tuple containing the same elements as the original but in sorted order.

tmp = list(t) tmp.sort( ) t = tuple(tmp)


Kaugnay na mga set ng pag-aaral

crucible act 1, 2, 3, 4 test review

View Set

AIMA Chapter 12: Knowledge Representation

View Set

Chapter 3 - Working with Financial Statements

View Set

Chapter 6: Disorders of the Breasts

View Set

Management History. The Next Level!

View Set