Yes, this is an appropriate edit.
Questions and answers on Stack Overflow naturally come with some fluff to establish the context of the specific situation. However, these are not literally relevant for the general case; other people finding the Q&A for their similar problem have to adjust these parts anyway.
Editing these parts does not change the content relevant for the Q&A. There is usually no loss of primary information when adjusting these incidental examples.1
Discussing every auxiliary details would be distracting, so ideally they conform to best practice. In the interest of maintaining a well-curated knowledge base, it is justified to adjust such examples when they are out of date.
[…] Common reasons for edits include:
- To correct minor mistakes or add updates as the post ages
1 Keep in mind that consistency of the entire Q&A may be relevant, though. Comparing question and answer code should reveal the relevant changes, not auxiliary improvements. Consider to adjust both the answer and question so that minor improvements do not draw undue attention.
s1 + s2 + s3
is poor style, but it recommendsstr.join
rather than string formatting as the alternative).