When using computers quite often we talk about standard input and standard output. Usually they correspond to keyboard and screen, respectively.
print(expr1, expr2, ..., exprn, sep=' ', end='\n') prints the values of
exprn to the standard output.
sepcontrols the string inserted between values. Default is space
endcontrols the string printed after the last value. Default new line
Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.
It is good practice to comment your code. The beginning of a comment in python is marked by
#. Everything that follows
# is ignored.
#this is a comment print("Hello world!") # this is also a comment, but after a bit of code ''' Comments can be also be marked by triple apostrophes especially when they are on several lines, but they also have a different meaning '''
Comments are very useful to explain others your code and understand your code when you return to it.
Commenting your code for:
# example how to use the sep parameter print ("Example without value for sep parameter: There are <", 2**32, "> possibilities!") print ("Example with value for sep parameter : There are <", 2**32, "> possibilities!", sep="")
Example without value for sep parameter: There are < 4294967296 > possibilities! Example with value for sep parameter : There are <4294967296> possibilities!
# example how to use the end parameter print("The first line") print("The second line")
The first line The second line
# when the end parameter is present. print("The first line", end="<br>") print("The second line", end="<br>")
The first line<br>The second line<br>
# print with no parameter prints an empty line print() print("This is after an empty line")
This is after an empty line
print "There are <", 2**32, "> possibilities!"
flushparameters will run in python2, but the result may look a bit different than expected
from __future__ import print_functionto use the
Read more about the
input(prompt=None) reads a string from the standard input. The trailing newline is stripped.
input("Please enter your name: ")
Please enter your name: Constantin Orasan
Note: input function returns a string and needs to be converted to a number if a number is expected (see more in the next sessions)
python2 has two input functions:
inputreturns a number
raw_inputreturns a string, but no longer available in python3