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
BeginnerInput 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__")
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Python for Kotlin Developers
1From Kotlin to Python
Run Your First Python ProgramPrint and String TemplatesVal, Var, and Python NamesDivision and Integer WidthSuites and Block ScopeRecap: Rewrite a Receipt4Iteration and Transformations
Ranges and Loop BindingsEntries and withIndexUpdates and Loop ControlCollection PipelinesRecap: Build a Ranking2Values and Decisions
Nullable Types and NoneEquality and IdentityBoolean Conditions and orIf Expressions and ElifRecap: Eligibility Rules3Collections and Shared State
Read-only Lists and MutationPair and Tuple UnpackingMap Lookup and Missing KeysShallow Copies and SetsRecap: Clean an Inventory6Input, Errors, and Modules
Console Input and FormattingExceptions and Resource ScopeImports and Entry PointsStatic Types and AnnotationsRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler