python function print value code example

Example 1: python print

# To print a string...
print("I am a string yay")

# To print an answer to an equation...
print(5+5)

# To print the answer of previously defined variables...
x = 50
n = 30
print(x + n)

# Notes:
# You can't add a string to a number.
x = "foo"
n = 50
print(x + n)
# That will come up with an error.

Example 2: print python

print('Hello, world!')

Example 3: python print

print("type what you want to be printed")

Example 4: python print advanced

# sep is between each item. empty string disables it.
print('hello', 'world', sep='')
##helloworld

# end is placed at the end of the statement. defaults to '\n' (line break)
print('The first sentence', end='. ')
print('The second sentence', end='. ')
##The first sentence. The second sentence. 

# file allows you to change where it sends the data
with open('file.txt', mode='w') as file_object:
    print('hello world', file=file_object)
## this would print "hello world" to a file named "file.txt"
# note: you can't use print for anything that isn't a character.

# use flush to disable buffering:
print(countdown, end='...', flush=True)