Menu
CoddyTech

cat, print, and Strings

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

R distinguishes console representations from plain text output: print often includes an index label and quotes, while cat writes values with chosen separators. Python print writes a readable string representation and ends with a newline by default. Both languages use a hash sign for comments outside strings. Python f-strings embed expressions in braces; an ordinary string preserves the braces. R commonly constructs text with paste or paste0 before emitting it. Single and double quotes are delimiters in both languages, not an automatic interpolation switch. Choose output intentionally rather than copying R console transcripts containing index labels into the expected program output.

R

name <- "Ada"
cat(paste("Hi", name), "\n", sep="")
cat("Hi {name}\n")

Python

name = 'Ada'
print(f"Hi {name}")
print("Hi {name}")

Porting trap

Use plain output for exact grading. Python print does not reproduce R's printed vector index labels.

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 R Developers

Practice on your own: Online Python compiler