PCEP-30-02 Exam QuestionsBrowse all questions from this exam

PCEP-30-02 Exam - Question 2


Assuming that the tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction:

Show Answer
Correct Answer: A

Tuples in Python are immutable, which means their elements cannot be changed once they are created. Any operation that tries to modify the contents of a tuple, such as assigning a new value to an element of a tuple, will result in a TypeError. Therefore, the statement 'my_tuple[1] = my_tuple[1] + my_tuple[0]' is illegal because it attempts to change an element of the tuple.

Discussion

10 comments
Sign in to comment
herrmann69Option: A
Jun 4, 2024

A is correct. TypeError: 'tuple' object does not support item assignment

consultskOption: A
Sep 30, 2024

Explanation: Tuples are immutable: This means that once a tuple is created, its elements cannot be changed. Any attempt to modify an element in a tuple, as shown in the code, will result in an error. Error: The code will raise a TypeError because Python does not allow the modification of elements in a tuple.

Supatekooma
Aug 7, 2024

my_tuple = (3, 5, 7) new_tuple = (my_tuple[0], my_tuple[1] + my_tuple[0], my_tuple[2]) 3,5 + 3,7 print(new_tuple) # The Given Instruction: # my_tuple[1] = my_tuple[1] + my_tuple[0] # This instruction tries to change the element at index 1 of my_tuple by adding the element at index 0 to it. # Attempting to Modify a Tuple: # Since tuples are immutable, any attempt to directly change an element in a tuple will result in a TypeError.

christostz03
Aug 20, 2024

a is the correct answer

Poojasr
Sep 3, 2024

option A

Vihaan_COption: A
Nov 3, 2024

Because tuples are immutable

Walied_AfroOption: A
Jan 27, 2025

cuz Tuples are immutable

ras_al_ghul1234Option: B
Feb 21, 2025

B is the right answer after strategical analysis.

KevinPerdomoOption: A
Mar 4, 2025

Tuples are immutable, that means it doesn´t support item assignment

ChandizOption: A
Apr 16, 2025

tuples are immutable, which means you cannot change their elements after creation.