Understand how to output text strings: Difference between revisions

From Computer Science Wiki
(Created page with "right|frame|Python programming language<ref>http://www.flaticon.com/</ref> This page is meant to be used in conjunction with media:Programming companio...")
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[file:python.png|right|frame|Python programming language<ref>http://www.flaticon.com/</ref>]]
[[file:python.png|right|frame|Python programming language<ref>http://www.flaticon.com/</ref>]]


This page is meant to be used in conjunction with  [[media:Programming companion Python.pdf | Our excellent resource for learning python]]
This page is meant to be used in conjunction with  [[media:Programming companion Python.pdf | 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 [[Understand serial files|different lesson]]).


You will also learn how to comment your code.


<syntaxhighlight lang="python">
# 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='--')
</syntaxhighlight>
If you are still stuck, or you have other questions,  you may want to [https://discuss.computersciencewiki.org/ '''ask a question on our discussion board'''].


== References ==  
== References ==  

Latest revision as of 08:34, 19 August 2021

Python programming language[1]

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.

References[edit]