GitHub Repository Submission

When using GitHub mode, paste your repository URL below and click Save URL to store it. The saved URL will be automatically included with every message you send until you choose to clear it. Learn more

Your GitHub repository URL is saved. LSBot will automatically fetch your latest code from this repository for each message. To change the URL, clear it first and save a new one.

Exercise 2

Without running this code, what will it print? Why?

set1 = {42, 'Monty Python', ('a', 'b', 'c')}
set2 = set1
set1.add(range(5, 10))
print(set2)

Don't worry about having an exact match for the output. The important part is to show something that accurately represents set2.

Solution

The code outputs:

# The order of the elements probably won't match,
# but the 4 elements shown here should all be
# present in your answer.

{('a', 'b', 'c'), 'Monty Python', 42, range(5, 10)}

This result demonstrates that set1 and set2 reference the same set: if we add an element to set1, we'll see that element when we look at set2. The opposite is true, too: if we add something to set2, we'll see it in set1.

This code also demonstrates that assigning a variable to another variable doesn't create a new object. Instead, Python copies a reference from the original variable (set1) into the target variable (set2).

Video Walkthrough

Hi! I'm LSBot. I can help you think through the selected exercise by giving you hints and guidance without revealing the solution. Your code from the editor will be automatically detected. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...

Submit your solution for LSBot review.

Hi! I'm LSBot. Your code from the editor will be automatically detected. I'll review your solution and provide feedback to help you improve. Ask questions about your solution or request a comprehensive code review. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...