noknow.dev
Sign inSign up
Course overview
Python Fundamentals
0 / 6 lessons0%

Getting Started

  • Hello, World!
  • Variables and Types
  • Working with Strings

Decisions & Loops

  • if / elif / else
  • for Loops and range()

Functions

  • Writing Your Own Functions

Working with Strings

0m 00s

Strings in Python

Strings (text) come with many useful built-in methods:

text = "  Hello, World!  "

print(text.upper())    # "  HELLO, WORLD!  "
print(text.lower())    # "  hello, world!  "
print(text.strip())    # "Hello, World!"  (removes surrounding spaces)
print(len(text))       # 18 (number of characters)

Joining and splitting strings

first = "Alice"
last = "Smith"
full = first + " " + last
print(full)            # Alice Smith

sentence = "red,green,blue"
colors = sentence.split(",")
print(colors)          # ['red', 'green', 'blue']

Checking for substrings

email = "test@example.com"
print("@" in email)    # True

Your task

Write a function format_name(first_name, last_name) that:

  1. Removes leading/trailing whitespace
  2. Capitalizes each part
  3. Returns "[Last], [First]"

Example: format_name(" alice ", "smith") → "Smith, Alice"

Back
pythonCtrl+Enter to run
Output

Click "Run" to execute your code.