Chapter 1 · Foundations

Text and input

You are reading the whole lesson on one page. Back to one step at a time

Step 1 of 20 · Concept

Text is a str

By the end of this lesson you can build text from values and read what the user types.

name = "Ada"
print(name)
print(len(name))

This prints Ada, then 3.

  • The quotes, "..." or '...', mark where the text starts and ends. They are not part of it.
  • len(text) counts the characters: len("Ada") is 3. A space counts too.
  • Text is a str object. It never changes, so the shorthand of lesson 3 may draw it in its name's box.
item = "Tea"
price = 2.5
print(f"{item}: {price * 3:.2f}")
print(f"{price=}")
item = "pencil"
count = 4
price = 1.25
# two lines, one f-string each
name = input("Name: ")
print("Hello, " + name)
age = int(input("Age: "))
price = float(input("Price: "))
print("In 3 years:", age + 3)
print("Two cost:", price * 2)
age = input("Age: ")
print("Next year:", age + 1)
# read the bill (a float) and the percent (an int)
# print the tip and the total, with two decimals
# write your program here
name = input("Name: ")
print(f"Hello, {name}!")
Terminal
Step 1 of 9A banner

Keyboard shortcuts

The step

ContinueEnter
Previous / next stepAlt+[ · Alt+]
Move along the steps bar← → Home End, then Enter
From a quiz's title to its answers↓
Skip to the stepTab, then Enter (first on the page)
Course outlineAlt+O
These shortcuts?

The workspace

Run the stepCtrl+Enter (⌘↵ on a Mac)
Lesson → editor → consoleF6 (Shift+F6 back)
Output ↔ TerminalCtrl+`
Focus the editorCtrl+. (⌘. on a Mac)
Hide or show the lessonAlt+L
Restore, close a messageEsc (outside the editor and the terminal)

The editor

Leave the editorF6 (Shift+F6 back); or Ctrl+M (⌃⇧M on a Mac), then Tab moves the focus (not in the vim mode)
Open a file by nameCtrl+P (⌘P on a Mac)
All commandsCtrl+Shift+P (⌘⇧P on a Mac) or F1
Go to a lineCtrl+G (⌃G on a Mac)
Show or hide the filesCtrl+B (⌘B on a Mac)
Previous / next file tabCtrl+Shift+[ · Ctrl+Shift+] (⌘⇧[ · ⌘⇧] on a Mac)
The file tabs← → Home End on a tab; Delete closes it
Save the files nowCtrl+S (⌘S on a Mac)
Go to a symbol in the fileCtrl+Shift+O (⌘⇧O on a Mac)
Go to the definitionF12
Format the fileCtrl+Shift+F (⌘⇧F on a Mac), or Shift+Alt+F
Go back / forward after a jumpAlt+← · Alt+→ (⌃- · ⌃⇧- on a Mac)