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 10
Assume that obj already has a value of 42 when the code below starts running. Which of the subsequent statements reassign the variable? Which statements mutate the value of the object that obj references? Which statements do neither? If necessary, you can read the documentation.
A simple assignment like var = something is always either an initialization or a reassignment. Since obj has already been initialized (it has a value of 42 before this code was reached), lines 1, 3, 5, and 10 perform reassignment. In a few situations, mutation and reassignment can happen in the same statement. None of the above statements do both.
obj.upper does not mutate the caller, so line 2 does neither. Likewise, since print, len, and set don't mutate their arguments, lines 4 and 9 are neither.
The remaining statements all mutate the object referenced by obj. pop removes the last element of the list. obj[2] = 'X' reassigns the element at index 2, but it mutates obj itself. Finally, sort mutates the object when it performs an in-place sort.
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...
Output
No output yet. Click "Run Code" to execute your code.
You can write code blocks using three backticks (```) followed by the language you want to show.
For instance, if you wanted to write a Ruby code block you would write:
```ruby
class Foo
end
```
class Foo
end
You can also leave out the language identifier, doing this will make it so your code isn't highlighted at all, and all text will be white with no coloring.
```
class Bar
end
```
class Bar
end
Highlighting
You may highlight lines within your code blocks. This is a different type of highlighting, and isn't related to how the code within your code block may be colored depending on the language identifier used.
To highlight one or more lines of code, add # highlight on a separate line just before the first line you wish to highlight. To end highlighting, add # endhighlight on a separate line immediately after the last line you wish to highlight.