Assignment, Equality, and Arithmetic
With some minor exceptions, Sage uses the Python programming language, so most introductory books on Python will help you to learn Sage.
Sage uses "=" for assignment. It uses "==", "<=", ">=", "<" and ">" for comparison:
Sage provides all of the basic mathematical operations:
The computation of an expression like "3^2*4 + 2%5" depends on the order in which the operations are applied; this is specified in the “operator precedence table” in Arithmetical binary operator precedence.
Sage also provides many familiar mathematical functions; here are just a few examples:
As the last example shows, some mathematical expressions return ‘exact’ values, rather than numerical approximations. To get a numerical approximation, use either the function "n" or the method "n" (and both of these have a longer name, "numerical_approx", and the function "N" is the same as "n")). These take optional arguments "prec", which is the requested number of bits of precision, and "digits", which is the requested number of decimal digits of precision; the default is 53 bits of precision.
Python is dynamically typed, so the value referred to by each variable has a type associated with it, but a given variable may hold values of any Python type within a given scope:
The C programming language, which is statically typed, is much different; a variable declared to hold an int can only hold an int in its scope.