ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Jul 2016 04:11:08 -0500Learning Python for Sagehttp://ask.sagemath.org/question/8301/learning-python-for-sage/Hi, I'm no expert in Python or Sage, but I want to learn Python specifically to help with Sage. I bought a book on Python programming and I'm trying out some of the stuff in Sage. But, some of it doesn't seem to work. So, I'm wondering... is this because Sage doesn't use Python 3 yet, or are there just some things with Python that don't work in Sage? If it's the second one, how can I know what's going to work and what's not? For example, in the book I have it says I should be able to do:
print("stuff stuff", end = " ")
print("stuff stuff")
and the effect is that instead of ending the print statement with "\n", it ends with a space so the second print statement prints on the same line. But, doing this in Sage 4.7 results in a syntax error, and it appears to not like the =.
ThanksFri, 02 Sep 2011 06:40:26 -0500http://ask.sagemath.org/question/8301/learning-python-for-sage/Answer by kcrisman for <p>Hi, I'm no expert in Python or Sage, but I want to learn Python specifically to help with Sage. I bought a book on Python programming and I'm trying out some of the stuff in Sage. But, some of it doesn't seem to work. So, I'm wondering... is this because Sage doesn't use Python 3 yet, or are there just some things with Python that don't work in Sage? If it's the second one, how can I know what's going to work and what's not? For example, in the book I have it says I should be able to do:</p>
<pre><code>print("stuff stuff", end = " ")
print("stuff stuff")
</code></pre>
<p>and the effect is that instead of ending the print statement with "\n", it ends with a space so the second print statement prints on the same line. But, doing this in Sage 4.7 results in a syntax error, and it appears to not like the =.</p>
<p>Thanks</p>
http://ask.sagemath.org/question/8301/learning-python-for-sage/?answer=12618#post-id-12618You might like looking at [this book](http://diveintopython.org/), which is the Python 2.x version of a very popular intro text.Fri, 02 Sep 2011 07:15:40 -0500http://ask.sagemath.org/question/8301/learning-python-for-sage/?answer=12618#post-id-12618Comment by slelievre for <p>You might like looking at <a href="http://diveintopython.org/">this book</a>, which is the Python 2.x version of a very popular intro text.</p>
http://ask.sagemath.org/question/8301/learning-python-for-sage/?comment=34153#post-id-34153Now at http://www.diveintopython.net after Mark Pilgrim removed diveintopython.org and most of his online presence.Wed, 20 Jul 2016 04:11:08 -0500http://ask.sagemath.org/question/8301/learning-python-for-sage/?comment=34153#post-id-34153Answer by Dima for <p>Hi, I'm no expert in Python or Sage, but I want to learn Python specifically to help with Sage. I bought a book on Python programming and I'm trying out some of the stuff in Sage. But, some of it doesn't seem to work. So, I'm wondering... is this because Sage doesn't use Python 3 yet, or are there just some things with Python that don't work in Sage? If it's the second one, how can I know what's going to work and what's not? For example, in the book I have it says I should be able to do:</p>
<pre><code>print("stuff stuff", end = " ")
print("stuff stuff")
</code></pre>
<p>and the effect is that instead of ending the print statement with "\n", it ends with a space so the second print statement prints on the same line. But, doing this in Sage 4.7 results in a syntax error, and it appears to not like the =.</p>
<p>Thanks</p>
http://ask.sagemath.org/question/8301/learning-python-for-sage/?answer=12617#post-id-12617print("stuff stuff", end = " ")
is certainly not valid in Python 2, and Sage is using Python 2, and switching is not going to
happen soon.
Actually, print is not a function in Python 2, so it's not that it doesn't like '=',
it doesn't like (), etc.
You can see few most common differences between Python versions 2 and 3 explained here: http://docs.python.org/release/3.0.1/whatsnew/3.0.htmlFri, 02 Sep 2011 07:11:51 -0500http://ask.sagemath.org/question/8301/learning-python-for-sage/?answer=12617#post-id-12617Answer by Simon King for <p>Hi, I'm no expert in Python or Sage, but I want to learn Python specifically to help with Sage. I bought a book on Python programming and I'm trying out some of the stuff in Sage. But, some of it doesn't seem to work. So, I'm wondering... is this because Sage doesn't use Python 3 yet, or are there just some things with Python that don't work in Sage? If it's the second one, how can I know what's going to work and what's not? For example, in the book I have it says I should be able to do:</p>
<pre><code>print("stuff stuff", end = " ")
print("stuff stuff")
</code></pre>
<p>and the effect is that instead of ending the print statement with "\n", it ends with a space so the second print statement prints on the same line. But, doing this in Sage 4.7 results in a syntax error, and it appears to not like the =.</p>
<p>Thanks</p>
http://ask.sagemath.org/question/8301/learning-python-for-sage/?answer=12624#post-id-12624Even in Python 2.7, you could import the print function from the future Python:
sage: from __future__ import print_function
sage: print("stuff stuff", end = " ")
stuff stuff sage: print("stuff stuff", end = " \n@\n")
stuff stuff
@
sage:
Sun, 04 Sep 2011 21:11:18 -0500http://ask.sagemath.org/question/8301/learning-python-for-sage/?answer=12624#post-id-12624