Strings & I/O

25 min
0/3 practice checks

A string is text. You can join strings with + (concatenation) and measure them with len():

greeting = "Hello, " + name n = len("hello") # 5

Strings have handy methods: "cape town".upper()"CAPE TOWN", " hi ".strip()"hi".

print(...) sends text to the screen; input(...) reads a line the user types (returns a string).

Code practice

Write a function greet(name) that returns the string "Hello, " followed by the name. For example greet("Zanele") returns "Hello, Zanele".

python

Runs in your browser. Charts (matplotlib) are not supported — use print-based output.

Code practice

Given s = "cape town", create a variable shout holding the uppercase version ("CAPE TOWN").

python

Runs in your browser. Charts (matplotlib) are not supported — use print-based output.

What does len("Caelum") return?