learning to program with Python

Discussion in 'Python' started by Ricardo, Feb 22, 2004.

  1. Ricardo

    Ricardo Guest

    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
    Ricardo, Feb 22, 2004
    #1
    1. Advertising

  2. Ricardo

    stewart Guest

    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
    stewart, Feb 23, 2004
    #2
    1. Advertising

  3. On Mon, 23 Feb 2004 06:15:32 GMT, stewart
    <> 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...

    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
    Dennis Lee Bieber, Feb 23, 2004
    #3
  4. 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
    Nicolas Fleury, Feb 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jbchua

    Learning to program in Python

    jbchua, Jan 5, 2007, in forum: Python
    Replies:
    6
    Views:
    261
    Paul Rubin
    Feb 4, 2007
  2. Hal Vaughan
    Replies:
    7
    Views:
    466
  3. Replies:
    5
    Views:
    423
  4. Andrew Savige
    Replies:
    10
    Views:
    440
    Hrvoje Niksic
    Jan 11, 2008
  5. Andrey Popp

    [I'm learning C]: Learning to use ucontext

    Andrey Popp, Jan 29, 2012, in forum: C Programming
    Replies:
    5
    Views:
    694
    Keith Thompson
    Jan 31, 2012
Loading...

Share This Page