By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

learning to program with Python

P: n/a
Hi, my name is Ricardo and i'm learning to program in Python with
version 2.3.3, i'm also using the latest version of PythonWin(163) but
i'm trying to do it with a book (Written in Portuguese) that covers the
version 2.1, and of course i'm having a problem. The code in wich i'm
having problems is as follows:

class Gato:
"um felino domesticado"
def __init__(self, sexo, corPelo=None):
self.sexo = sexo
if corPelo != None
self.corPelo = corPelo
def miar(self):
if self.sexo == "m":
return "MIAU"
else:
return "miauuuu"
the book says that it should be done like this, but when i finnish the
5th line(if corPelo != None) and press ENTER, it gives me the error:

Traceback ( File "<interactive input>", line 5
if corPelo != None
^
SyntaxError: invalid syntax

I hope someone can help me?
Thanks in advance anyway.

Ricardo
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ricardo wrote:
The code in wich i'm
having problems is as follows:
.... if corPelo != None
self.corPelo = corPelo

....

Oi Ricardo, tudo bem?

I see at least two problems here. Python requires brackets around the 'if'
comparison, and a colon at the end of the if statement. Try re-writing
your statement as:
if (corPelo != None):
self.corPelo = corPelo

Boa sorte!
S

Jul 18 '05 #2

P: n/a
On Mon, 23 Feb 2004 06:15:32 GMT, stewart
<st*****@midtoad.homelinux.org> declaimed the following in
comp.lang.python:
I see at least two problems here. Python requires brackets around the 'if'
comparison, and a colon at the end of the if statement. Try re-writing
The colon is needed, yes... but not the parentheses...

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 18 '05 #3

P: n/a
stewart wrote:
I see at least two problems here. Python requires brackets around the 'if'
comparison, and a colon at the end of the if statement. Try re-writing
your statement as:
if (corPelo != None):
self.corPelo = corPelo


No, Python doesn't require parenthesis or brackets around the
comparison. Any expression can have optional parenthesis.

if corPelo != None:
self.corPelo = corPelo

is enough.

Regards,

Nicolas
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.