01 / GETTING STARTED · LESSON 03

Strings that say what you mean

Clean a hostname and produce a readable message.

11 min · learn at your pace

Text has its own tools

A string is a sequence of characters. Methods are functions attached to a value: name.strip() removes surrounding whitespace, and name.lower() changes letters to lowercase. Strings are immutable, so these methods return new strings. Save the returned value if you need it later.

Use len(name) to count characters. Indexing such as name[0] starts at zero. Do not rely on a particular host naming convention to tell you whether an address is safe or valid; here we are only formatting supplied text.

Put values into a sentence

An f-string begins with f before its quote. Expressions inside braces are evaluated and inserted into the text. This keeps the calculation or conversion visible beside the words it describes. A format like f"{ratio:.1f}" rounds the displayed value to one decimal place without changing the original number.

Single and double quotes work equally well. Pick whichever makes a message easier to read. \n inside a normal string represents a newline; it is not the same as putting two separate print calls on one physical line.

Try an example.py
raw_name = "  web-02  "
hostname = raw_name.strip().upper()
print(f"{hostname}: ready")
YOUR TURN

Put it into practice.

Clean raw_name by stripping whitespace and uppercasing it into hostname. With memory_gb = 24, store and print the message SRV-WEB-01: 24 GB RAM.

See an explained solution
One way to solve it.py
raw_name = "  srv-web-01  "
memory_gb = 24
hostname = raw_name.strip().upper()
message = f"{hostname}: {memory_gb} GB RAM"
print(message)

The methods create the cleaned hostname. The f-string converts the integer for display while memory_gb remains numeric.