Menu
CoddyTech

Echo, Strings, and print

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

PHP files enter code with <?php and typically end statements with semicolons. Python files need neither. PHP echo adds no separator or newline; Python print separates arguments with a space and appends a newline. PHP interpolates variables in double-quoted strings; Python ordinary strings do not interpolate names. Use an f-string when inserting a value. Python single and double quotes both create strings, so choose the delimiter that avoids escaping. A Python comment begins with #; PHP // is floor division in Python.

PHP 8.3

<?php
$name = 'Ada';
echo "Hi $name", "!", "\n";

Python

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

Porting trap

PHP concatenates with . and can convert a number during concatenation. Python + joins strings only when both operands are strings. Use str(count) or an f-string instead of expecting numeric coercion.

Complete the task in the editable Python files. Keep the required function and class names; the locked driver.py supplies execution.

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

Practice on your own: Online Python compiler