~gasp-lessons-team/gasp-lessons/gasp-lessons

« back to all changes in this revision

Viewing changes to gasp_course/source/I-inout.rst

  • Committer: Jeffrey Elkner
  • Date: 2019-02-28 20:10:57 UTC
  • Revision ID: jeff@elkner.net-20190228201057-16ow1gbbdwc2on02
Update I-sheet to Python3

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
------------
7
7
 
8
8
Almost any interesting program has to get information from somewhere, and
9
 
produce some sort of answers somewhere. These are called input and output .
 
9
produce some sort of answers somewhere. These are called input and output.
10
10
This sheet describes some of the ways Python handles input and output.
11
11
 
12
12
Some of the things in here require you to have done
78
78
    >>> y = 'zog'      # a string,
79
79
    >>> z = 99         # a number,
80
80
    >>> f = repr       # a function
81
 
    >>> print x, y, z, f
82
 
    [1, 2, 3] zog 99 
 
81
    >>> print(x, y, z, f)
 
82
    [1, 2, 3] zog 99 <built-in function repr>
83
83
 
84
84
Notice that it puts spaces between the things it prints.
85
85
 
86
86
If you write two ``print`` statements, one after the other, you'll see that the
87
87
second starts printing on a fresh line rather than following on from the first.
88
 
If that isn't what you want, put a comma at the end of the first ``print``:
 
88
If that isn't what you want, put ``end=' '`` inside the first ``print``:
89
89
 
90
90
.. sourcecode:: python
91
91
    
92
 
    print 123,
93
 
    print 456
 
92
    print(123, end=' ')
 
93
    print(456)
94
94
 
95
95
This will print ``123 456`` on a single line.