Presentation is loading. Please wait.

Presentation is loading. Please wait.

Printing in Python. Printing Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external.

Similar presentations


Presentation on theme: "Printing in Python. Printing Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external."— Presentation transcript:

1 Printing in Python

2 Printing Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files used for output The function used in Python is print. It can have as many arguments as you wish Syntax: print ( arguments ) The argument list can use variables, expressions, constants The argument list can also be empty print()

3 Semantics of print When the print function is called, it evaluates the arguments and displays them on the shell window It displays them starting wherever the cursor is at the time If there is more than one argument, there will be one space put between them on the screen When it finishes displaying them, it will output a “newline” character (also called a carriage return) This moves the cursor to the left side of the screen and down to the next line. print() is one way to output just a newline character

4 Extra arguments for print To give the programmer a little more control over the exact positioning of the outputs, there are some extra arguments you can use in the parentheses end= will specify what the print function should output when the list of arguments to output is finished sep= will specify what should be put in between the arguments to separate them (note that this is just between arguments, not at the end of the line) These have string values Example: print(“abc”, “def”, sep=“++”) outputs abc++def on one line

5 Example of end= print(“joe”, end=“ “ ) that’s a space between the quotes Would output joe on the screen wherever the cursor was at that time and then a space and then the cursor would stay on that line. It would NOT move to the next line.


Download ppt "Printing in Python. Printing Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external."

Similar presentations


Ads by Google