Python - Print

Card Puncher Data Processing


print ("%s" % (string_variable))


  • the first Parenthese are only needed for python 3 as print is a function.
  • The % string formatter replace
  • The %s (%s is a place holder where the “s” is for “string”)
  • with string_variable


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

Discover More
Card Puncher Data Processing
Python - String (str type)

in Python A string literal is a sequence data type. Strings in Python are: sequence with characters as elements Each character in a string has a subscript or offset (id). The number starts at...

Share this page:
Follow us:
Task Runner