Table of Contents

Python - Print

Syntax

print ("%s" % (string_variable))

where:

Example

Python 2

print "My last name is %s and my first-name is %s" % ("Gerard", "Nico")

Python 3

In python 3, print becomes a function

print ("My last name is %s and my first-name is %s" % ("Gerard", "Nico")) 

No new line

By appending a , at the end of the statement, you prevent the print function to add a newline

print "Lines without",
print "New Line",
Lines without New Line

Explicit Number transformation and String Concatenation

dictionary = {'key1': 1, 'key2': 2, 'key3': 3}

for key in dictionary:
    print key, ":" ,  dictionary[key]
key3 : 3
key2 : 2
key1 : 1