Menu
CoddyTech

Print and String Templates

Lesson 2 of 48 in Coddy's Python for Kotlin Developers course.

Kotlin println takes one value, while Python print accepts multiple positional values and inserts spaces. Python strings need an f prefix to evaluate expressions in braces; ordinary strings leave dollar signs untouched. Kotlin has a distinct Char type for single quotes; Python uses str for both single- and double-quoted text. Python source executes at module level without a fun main wrapper. Use # for comments: Kotlin's // spelling is floor division in Python.

Kotlin

fun main() {
    val name = "Ada"
    println("Hi $name!")
}

Python

name = "Ada"
print(f"Hi {name}", "!")

Porting trap

Do not expect Python "Hi $name" to interpolate as a Kotlin string template does. Use f"Hi {name}". Python print adds a newline unless its end argument changes it.

Complete the task in its editable modules. The locked driver.py supplies execution; keep the required API names.

challenge icon

Challenge

Beginner

Input is one line of text, which may be empty or contain quotes or #. Print Message:, one space, and that exact text on the first line. Print It's Python on the second line. Remove or comment out the diagnostic print in the starter. input() is supplied here to read one line without its final newline.

Print only the requested output, with a newline after each line. The supplied input lines read the test data; keep them and add your work below.

Your code goes in main.py. The locked driver.py starts your program and cannot be edited.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Python for Kotlin Developers

Practice on your own: Online Python compiler