Slicing cuts out a piece of a string by position range. Both languages use start is included, end is excluded, the slice [0:4] takes indexes 0, 1, 2, 3 and stops before 4.
EXAMPLE
loading editor…
YOUR TURN
Your turn → Slice out just "ming" from the word.
loading editor…
Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.
Concatenation glues strings together with +. But for building sentences, both languages have something better: template strings, which let you drop variables straight into text.
Template strings
PYTHON
name = "Zora"
print(f"Welcome back, {name}.")
≈
JAVASCRIPT
let name = "Zora";
console.log(`Welcome back, ${name}.`);
Compare → Python prefixes the string with f and uses {name}. JavaScript uses backtick quotes and ${name}. Both beat gluing pieces with + signs.
EXAMPLE
loading editor…
YOUR TURN
Your turn → Rewrite the sentence about an artist or writer you admire, using two variables.
loading editor…
Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.
Mark this lesson complete
Signed in, your progress follows you to every device.