Skip to content

Commit f89a5f7

Browse files
hjwpbmispelon
authored andcommitted
Add a brief description of the print statement
We start using print later on, but it hasn't been explained. This shows why you might want to use it instead of just letting the interpreter give you the repr of a variable.
1 parent 03b9601 commit f89a5f7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

python_introduction/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ Awesome, right? Of course, variables can be anything, so numbers too! Try this:
150150

151151
Play with this for a while and see what you can do!
152152

153+
154+
## The print function
155+
156+
Try this:
157+
158+
>>> name = 'Maria'
159+
>>> name
160+
'Maria'
161+
>>> print(name)
162+
Maria
163+
164+
When you just type `name`, the Python interpreter responds with the string *representation* of the variable 'name', which is the letters M-a-r-i-a, surrounded by single quotes, ''. When you say `print(name)`, Python will "print" the contents of the variable to the screen, without the quotes, which is neater.
165+
166+
As we'll see later, `print()` is also useful when we want to print things from inside functions, or when we want to print things on multiple lines.
167+
168+
153169
## Lists
154170

155171
Beside strings and integers, Python has all sorts of different types of objects. Now we're going to introduce one called __list__. Lists are exactly what you think they are: they are objects which are lists of other objects :)

0 commit comments

Comments
 (0)