[Tutor] functions

Alan Gauld alan.gauld at btinternet.com
Tue Dec 15 07:55:19 EST 2015


On 15/12/15 11:19, Matthew Lintern wrote:

> def myfun(x):
>     y=x**2
>     return y
> 
> print myfun(5)
> 
> However, Spyder tells me there's a syntax error with myfun(5).

I suspect that the video is for Python v2 and you are using
Python v3. v3 was a major change in the language and on of
the biggest was that print is now a function and therefore
needs parentheses around its arguments.
So your code should look like:

print( myfun(5) )

My recommendation is that you try to find a set of
python v3 videos. Alternatively download Python v2.7
and use that with the v2 videos, then when you are
ready to upgrade to v3 you can look at one of the
many resources on migrating from 2->3.


BTW One alternative source outside Youtube is
Showmedo.com. Some of them are paid for but many
are free.

http://showmedo.com/videotutorials/python

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list