Courseiva
Strings →hardMultiple Choice

PCAP Strings Practice Question

Given the code: s = 'Python'; t = s; s = s + '3.0'. What is the value of t after these lines execute?

⚠ Common exam trap

Python Institute often tests the misconception that variable assignment creates a copy of the value, when in fact it creates a reference; candidates mistakenly think `t` will reflect the new value of `s` after reassignment.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

'Python'

Strings in Python are immutable. The assignment `t = s` makes `t` reference the same string object as `s`. When `s = s + '3.0'` executes, a new string object `'Python3.0'` is created and bound to `s`, while `t` still references the original string `'Python'`. Thus, `t` remains `'Python'`.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    It raises an error because s was reassigned.

    Why it's wrong here

    In Python, reassigning a variable is always legal; the name s is simply rebound to a new object. The earlier assignment t = s already stored a reference to the original string object, so no exception is raised when s is later rebound. Therefore this option is incorrect.

  • ✗

    ''

    Why it's wrong here

    An empty string would require t to be bound to a new object created by some operation, but t is never reassigned in the code shown. The variable t still holds the reference that was copied from s before s was rebound. Consequently the output cannot be an empty string, because t's binding remains unchanged.

  • ✗

    'Python3.0'

    Why it's wrong here

    The value 'Python3.0' would be the result of the concatenation assigned to s, but that operation creates a brand-new string object rather than mutating the original. Since strings are immutable, the object that t references cannot be altered in place, so t still points to the original 'Python' object. Hence this option is incorrect.

  • ✓

    'Python'

    Why this is correct

    When t = s executes, both variables reference the same immutable string object containing 'Python'. Later, s = s + '3.0' creates a new string object and rebinds only s; t remains bound to the original object. Therefore printing t outputs 'Python'.

About these practice questions

This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.