SageMathOER-CCC / sage-discrete-math

An open textbook for Discrete Mathematics with SageMath, as taught at the City Colleges of Chicago
https://sagemathoer-ccc.github.io/sage-discrete-math/
Other
2 stars 2 forks source link

Chapter Set Theory #100

Closed hcolmanccc closed 2 weeks ago

hcolmanccc commented 3 weeks ago

I cannot see anywhere in this chapter how to enter a list that is not made of numbers.

Explain here how to do that, or if it is done before (I did not find it) include an example like the set of letters a, b, c.

hcolmanccc commented 2 weeks ago

M = Set(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]) M

Is single or double quotation interchangeable?

Samuel-Lubliner commented 2 weeks ago

Sage follows PEP 0008 https://doc.sagemath.org/html/en/developer/coding_basics.html

From https://peps.python.org/pep-0008/#string-quotes "In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability."

Unfortunately, Sage does not "Pick a rule and stick to it"

Zimmerman seems to prefer double quotes.

image

When you evaluate double quotes in a sage cell, the output will be converted to single quotes.

The only way to use a single quote in a string is to encase it in double quotes or else you will get an error. If you enter the following in a SageCell you will see:

Input:

"string"

Output:

'string'

Input:

"Sam's string"

Output:

"Sam's string"

Input:

'Sam's string'

Output:

  Cell In [1], line 1
    'Sam's string'
                 ^
SyntaxError: unterminated string literal (detected at line 1)