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
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 PHP Developers
1From PHP to Python
Run Your First Python ProgramEcho, Strings, and printVariables Without Dollar SignsDivision and Numeric TextIndentation and SuitesRecap: Rewrite a Receipt4Iteration and Transformations
Foreach and rangeKeys, Items, and enumerateWhile Without IncrementFilters and Sort KeysRecap: Build a Ranking2Values and Decisions
Null, None, and Missing KeysStrict Equality Is Not isThe Zero String TrapElif and Value SelectionRecap: Eligibility Rules3Arrays and Python Collections
PHP Arrays and Python ListsDestructuring and TuplesKeys, Null, and getArray Copies and List AliasesRecap: Clean an Inventory6Input, Errors, and Modules
CLI Input and Exact OutputConversion Errors and CleanupImports Instead of requireType Hints Are Not PHP TypesRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler