1 of 8

1

2 of 8

  • Use the print command to write text to the screen
  • Newline character from the print statement
  • Commenting

3 of 8

Ancient African Mathematics

The Ishango Bone is one of the oldest mathematical artifacts in existence, unearthed in 1950 in the area of Ishango near the Semliki River, now known as the Democratic Republic of Congo. The central column begins with 3 notches and then doubles to 6 notches, repeats with 4 to 8 notches, and then 5 to 10. Scholars suggest the numbers indicate an understanding of the principle of prime numbers, multiplication, division, or the lunar calendar.

The Ishango Bone is now housed at the Museum of Natural Sciences in Brussels, Belgium,

4 of 8

Printing to the console

As you learn Python, you will write code in the text editor to the left. Use a print command to see the output of your program. Enter the code below (or copy/paste the code) and click the TRY IT button.

print("Hello Black World")

The reason you were able to see the words appear is because of the print command. Change your code to look like this and run it again.

"Hello Black World"

5 of 8

Newline Character

The print command automatically adds a newline character each time you use it. This is the default behavior. The code below will not print the two words on the same line. Enter the code below (or copy/paste the code) and click the TRY IT button.

print("Hello")

print(“Black”)

print("World")

The text in red shows the newline character which is added even if you do not type it. (The newline character is what is inserted when you press “Enter” or “Return”).

print(“Hello, Black World”, end =’\n’)

6 of 8

Removing the Newline Character

Add , end='' (two quotes with nothing between them) to your print command. This overrides the default newline character.

print(Hello, “, end=)

print(“Black “, end=”)

print(“World “)

What happens if you:

  • Use double quotes instead of single quotes with end=''
  • Use end='\t' in the print command
  • Use end='!' in the print command

7 of 8

Comments

You may have wondered why a couple of lines of code are a different color (in the below example, light brown, but it depends on the Theme you have picked):

In Python, to write notes in code without affecting it’s function we can use # to make a comment

Comments can also be used to help you fix your code. You can “comment out” lines of code that are not working or you suspect are causing problems.

8 of 8

Comment Blocks

To make a multi-line comment you can either combine the single line characters # or wrap the set of lines in triple quotes (''').

'''

This is a multi-line comment

You can then easily end the comment with a triple quote

'''

print("Notice code that runs is not the same color as single-line comments");

print("This feature is called syntax highlighting");

print("It is a common feature of IDEs");

The syntax highlighting is different for comments with #and comments with '''. That is because the triple quotation marks are also used for multi-line strings (see the Strings lesson). When a multi-line string is by itself (no print statement), then Python treats it as multiline comment.