Home -> Display Print


The commands for displaying and printing are not entirely clear to me.

nothing - apparently if the last line of code is a command, but not defined as an object, its "value" will be displayed.

print - here you don't want parentheses. You want a blank and then an object name. Since I work online, print doesn't actually print, it displays. If separate object names by commas, they will print on the same line. If you want separate lines, use separate lines with print (with no comma at the end). (Why sometimes the lines are not wrapped and scroll off the page is beyond my comprehension.)

view() is also a command for displaying the value of an object? (Many of my earlier pages use this command and not print. Then I decided I liked print because I could get more than one object on a line.)

show() is a command for displaying one or more plots previously defined as objects in a single plot box (2d or 3d). The different objects inside the show command are separated by + signs, not commas. (You will often see me use the sum command and a list of objects.)

Example 1 - nothing

len([1,2,3])
Result:
3

Example 2 - nothing but defined as an object

ct=len([1,2,3])
No Result

Example 3 - value of object printed

ct=len([-1,1,3])
print ct
Result:
3

Example 4 - "value" of two objects printed on one line

list1=[j for j in [-1..3,step=2] ]
ct=len(list1)
print list1, ct
Result:
[-1, 1, 3] 3

Example 5 - "value" of two objects printed on separate lines

list1=[j for j in [-1..3,step=2] ]
print list1
ct=len(list1)
print ct
Result:
[-1, 1, 3]
3

Example 6 - plot y=2x and the point (2,1)

F=plot(2*x,(x,-2,2))
P=point((3,1), size=20, color='red')
show(F+P, figsize=3)


Example 6

show_display.png
Keywords: display, print, view, show, sage