Understand how to output text strings: Difference between revisions
Mr. MacKenty (talk | contribs) No edit summary |
Mr. MacKenty (talk | contribs) No edit summary |
||
Line 8: | Line 8: | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
# a normal hello world print | # a normal hello world print function in python: | ||
print("hello world") | print("hello world") | ||
print("from Warsaw") | print("from Warsaw") |
Latest revision as of 07:34, 19 August 2021
This page is meant to be used in conjunction with our excellent resource for learning python
For this topic we are learning how to output text string to the screen. You can also output text strings to a file (but that is a different lesson).
You will also learn how to comment your code.
# a normal hello world print function in python:
print("hello world")
print("from Warsaw")
# This is a handy to print many characters X number of times. I like to use this to visually separate output.
print("=" * 25)
# we will now look at the end keyword argument:
print("hello world", end='')
print("from Warsaw")
print("=" * 25)
# let's try a different end keyword argument:
print("hello world", end=' -- foo --')
print("from Warsaw")
print("=" * 25)
# we will now look at the sep keyword argument (what should we output between strings)
print("Hello","world", sep='..')
print("from","Warsaw", sep='--')
If you are still stuck, or you have other questions, you may want to ask a question on our discussion board.