Lesson 04 of 55
9 mins readPython Operators: Math, Dot (.) Concatenation & Comparisons
In Plain English
Perl uses distinct operators for numbers and strings. For example, `+` is arithmetic addition, while `.` is string concatenation. Numeric equality uses `==`, whereas string equality uses `eq`.
Deep Dive: How It Works
String Concatenation (.): Combines two strings: "Hello " . "World".
String Repetition (x): Multiplies strings: "-" x 10 produces "----------".
Numeric Comparisons: ==, !=, <, >, <=, >=, <=> (spaceship).
String Comparisons: eq, ne, lt, gt, le, ge, cmp (three-way string comparison).
Core Rules to Remember

Dot (.) for Strings, Plus (+) for Numbers: Never use `+` to concatenate strings in Perl; use the dot `.` operator.

eq vs ==: Use `==` for numeric equality and `eq` for string comparison.
Live Interactive Example
Hit Run Code to see it liveNumeric and String Operations
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Output Console
Click "Run Code" to view the rendered output.
How it works: . concatenated strings and "x" 20 created 20 equals signs.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
String and Math Concatenation
Calculate `my $total = 50 * 2;`
Print `"Total: " . $total . "\n"` using the concatenation dot operator.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.