Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004

# The pound sign--also known as "crunch", "hash", "number sign", or "octothorpe"--denotes a comment
Look at the following code. It assigns values to a and b and then their sum to c.

Note that when you press the Enter key in Sage Notebook the expression is not evaluated. Either click "evaluate" or press Shift-Enter. Do so now.

a=3 b=2 c=a+b

Note that assignments are evaluated but not displayed. To display a previously defined variable, type its name on a line by itself or in a different input cell.

c
5

Like Python, changing the value of a will not change the value of c.

a=7 c
5

Comparison to Python

1. The exponent operater. Evaluate the following cell in both Sage and Python modes. When executed in Python, 4^2=6. Python inherited the designation of '^' as the bitwise XOR operator from C/C++. For an explanation of  bitwise XOR, see: http://irc.essex.ac.uk/www.iota-six.co.uk/c/e4_bitwise_operators_and_or_xor.asp

d=3**2 print 'd = ',d e=4^2 print 'e = ',e
d = 9 e = 6

2. Division with '/'. Evaluate the following cell in sage and Python

d=10/5 print 'd = ',d e=2/3 print 'e = ',e
d = 2 e = 0