print to console python code example

Example 1: how to print to command line python

print ('Hello, world!')

Example 2: how to print to console python

print(value)

print("Hello, World!") # String
print(3) # Number
print(True) # Boolean

# Can also print a variable.

Example 3: print in python 2

# Print is a keyword in python2, so it works more like this
print ""

# Also like this
print 1+1

Example 4: python text ouput to console

#in python 2.7
print "Hello world"
#in python 3.7
print("Hello again world")

#Neither of these require any imports.

Example 5: what is the correct way to output a string to the console in python

time = datetime.now() #2014-07-08 13:08:09

print "%02d:%02d:%02d" % (time.hour, time.minute, time.second)