Title: Print Statement Examples
Course: CPS 120: Introduction to Computer Science ~ Master (Aug/2015) OLD > Section: Learning Units

Python Print Statement Examples

# print statement examples
# No separator parameter specified, so default is space character.
# No end-of-line parameter specified, so default is newline character.

print ("1-Hello World!")
print ("2-", "Hello", "World!")
print (3, "-", "George Washington was born in", 1732)
print (4, "-", "The average test score was", 82.5)
print ("5-", "The answer to Question 7 is", True)

1-Hello World!
2- Hello World!
3 - George Washington was born in 1732
4 - The average test score was 82.5
5- The answer to Question 7 is True

Python print statement examples with “sep” parameter

# print statement examples with "sep" parameter
print ("6-", "Hello", "World!", sep="#")
print ("7-", "Hello", "Earth!", sep="--")

6-#Hello#World!
7---Hello--Earth!

Python print statement examples with “end” parameter

# print statement examples with "end" parameter
print ("8-", "Hello", "Detroit!", end="#")
print ("9-", "Hello", "Chicago!", end="--")
print ("10-Hello Cleveland!")
print ("11-Hello Milwaukee!", end="*")

8- Hello Detroit!#9- Hello Chicago!--10-Hello Cleveland!
11-Hello Milwaukee!*

More Examples

Identical Python print statement examples without and with “end” parameter:

# Identical print statement examples, without and with "end" parameter
print ("12-Hello Cincinnati!")
print ("12-Hello Cincinnati!", end="\n")

12-Hello Cincinnati!
12-Hello Cincinnati!

Python print statement example with “sep” and “end” parameters:

# print statement example with "sep" and "end" parameters
print ("13-", "Hello", "Pittsburgh!", sep="%", end="&")

13-%Hello%Pittsburgh!&