Skip to content

Text (strings)

Anything inside quotes is called text in programming (the technical word is string). Python can do some surprisingly fun things with text.

The + sign glues two pieces of text together:

Inputs (for input())

One value per line — read in order by input().

Output
 

Notice: if you don’t leave a space after "Hello,", the words come out stuck together. Try it! 🙂

The * sign repeats text as many times as you want:

Inputs (for input())

One value per line — read in order by input().

Output
 

"=" * 30 — thirty equals signs in a row. A great trick for drawing tables and frames.

Either works — Python doesn’t care:

print("Hello")
print('Hello')

But if the text has a quote inside it, pick a different one for the outside:

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Glue it together

+10 XP

Use + to join two pieces of text so the screen shows exactly Python rocks.

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Laughter generator

+10 XP

Use * to print hahahahaha to the screen — but write the word "ha" only once!

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Framed name

+15 XP

Frame your name between lines made of = signs — a line on top, your name in the middle, a line below.

Inputs (for input())

One value per line — read in order by input().

Output
 

Next lesson: numbers and math — Python is far more powerful than your pocket calculator. Continue →