Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Displaying results of calculations


Before we go any further, we need to learn about the print function. print takes one argument, which is enclosed in parenthesis. print evaluates its argument and writes the result to either the interactive shell or an output cell in a worksheet. If the argument is a string, print simply prints the string. If the argument is another type, it will be converted to a string before being printed. By default, each call to the print function will result in a new line of output. For example, enter the following code in an input cell to see how print works in a worksheet:

print('This is a string')
print(1.0)
print(sqrt)

The result looks like this:

We'll use print extensively to display the output from Sage calculations. In older Python code, you will often see print used as a statement instead of a function:

print 'This is a string'

Python versions 2.6 and later support using print as either a statement or a function. However, in Python 3 and later only the function...