print "Hello, world!"
A print statement is the easiest way to get your Python program to communicate with you. Being able to
command this communication will be one of the most valuable tools in your programming toolbox. -
Answers
There are two different Python versions. Both Python 2 and Python 3 are used throughout the globe.
The most significant difference between the two is how you write a print statement. In Python 3, print
has parentheses.
print("Hello World!")
print("Deep into distant woodlands winds a mazy way, reaching to overlapping spurs of mountains
bathed in their hill-side blue.")
In this course we will be using Python 2. If you go on to write Python 3 it will be useful to note this key
difference. - Answers
Text in Python is considered a specific type of data called a string. A string, so named because they're a
series of letters, numbers, or symbols connected in order — as if threaded together by string. Strings can
be defined in different ways: - Answers print "This is a good string"
print 'You can use single quotes or double quotes for a string'
While double-quotes (") and single-quotes (') are both acceptable ways to define a string, a string needs
to be opened and closed by the same type of quote mark.
We can combine multiple strings using +, like so:
print "This is " + "a good string"
This code will print out "This is a good string". - Answers
Try adding your name to the print statement with the + operator so that this Python program prints
"Hello [your_name]" - Answers print "Hello " + "Jennifer"
Here are some common errors that we might run into when printing strings:
, print "Mismatched quotes will cause a SyntaxError'
print Without quotes will cause a NameError
If the quotes are mismatched Python will notice this and inform you that your code has an error in its
syntax because the line ended (called an EOL) before the double-quote that was supposed to close the
string appeared. The program will abruptly stop running with the following message:
SyntaxError: EOL while scanning a string literal - Answers This means that a string wasn't closed, or
wasn't closed with the same quote-character that started it.
Another issue you might run into is attempting to create a string without quotes at all.
Python treats words not in quotes as commands, like the print statement.
If it fails to recognize these words as defined (in Python or by your program elsewhere) Python will
complain the code has a NameError. This means that Python found what it thinks is a command, but
doesn't know what it means because it's not defined anywhere. - Answers
Python uses variables to define things that are subject to change. - Answers
greeting_message = "Welcome to Codecademy!"
current_excercise = 5
In the above example, we defined a variable called greeting_message and set it equal to the string
"Welcome to Codecademy!". It also defined a variable called current_exercise and set it equal to the
number 5. - Answers
Create a variable called todays_date and assign a value that will represent today's date to that variable.
todays_date = "March 31, 2023" - Answers
Python also offers a companion to division called the modulo operator. The modulo operator is
indicated by % and returns the remainder after division is performed. - Answers
is_this_number_odd = 15 % 2
is_this_number_divisible_by_seven = 133 % 7