Why Are Python List Operations/Methods Unlike Python String Operations/Methods?

Problem scenario
List operations such as .sort() will change previous copies of the list.

String operations such as .replace(“old_pattern”, “new_pattern”, count), will not change the variable or its copies; these operations will return a string after the replace operation has run on the original string.

Why is this behavior happening?

Solution
In-place changes and mutability are factors.

How Do You Troubleshoot “SyntaxError: invalid syntax” in Python?

Problem scenario
You are running a Python script. You keep getting “SyntaxError: invalid syntax” and a line number. You can find nothing wrong with the syntax on the specified line number. What do you do?

Possible solution #1
Look at the line with code, as opposed to blank line(s), above it. Is there a missing quote, brace, bracket or parentheses?

Possible solution #2
Are you trying to use an “if” statement on one line?

How Do You Pass Two or More Subnets to an “aws eks” Command?

Problem scenario
You want to pass more than one subnet to an “aws eks” command.

You tried to delimit the list with commas (or separate two subnet IDs with commas). You received this error message:

An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: The subnet ID ‘subnet-0abcd1234,subnet-zyxw9876’ does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidSubnetID.NotFound; Request ID: Proxy: null)

What should you do?

What Does the Number “2” in a man Command Mean?

Question
Normally when you use the man page, you just type man nameofcommand. But you have seen integer numbers between 1 and 9 (inclusive) between the “man” and the command’s name. What do those numbers signify?

Answer
This legend was taken from “man man” on a Linux server:

1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), …

Why in Python Does a Variable Copy Get Changed when You Change Its Source?

Problem scenario
You have a list in Python that you copy into another variable. You change the original list and the copied version changes. Why does the copied version get copied and what can you do to overcome this?

Solution
There is something called a “deep” copy and a “shallow” copy. This program will illustrate both the problem and the solution:

list_a = [3, …