New to Python; Command equivalents

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Code_Dark

    New to Python; Command equivalents

    Hi, I'm new to the Python programming language, and eager to learn. I
    know C and C++, but I'm sure you all know that feeling when you just
    _need_ a new language. I chose python because I'd heard good things
    about it. I have python 2.3 installed on my computer, and I am glad to
    say that I've created a "Hello, World" program. Right, the only
    problem is that the only command I've been able to figure out is
    'print'. That's quite a problem. I was just wondering if someone could
    give me the command for 'cin' or 'scanf' in the C-based languages,
    and if it is required to define variabled before using them as in the
    C based languages (such as ;int numbofPizza' in the beginning of the
    program). Sorry for asking such newbieish questions, but I am, in
    fact, a newbie. Please reply to this, or email me at
    dshaw858@hotmai l.com ... the email address I use for my newsgroups
    (rooting_j00@ho tmail.com) isn't regularly checked because of spam...
    meh.

    Thanks in advance,

    - Code Dark
  • John Roth

    #2
    Re: New to Python; Command equivalents


    "Code_Dark" <rooting_j00@ho tmail.com> wrote in message
    news:8f43ba42.0 311042330.7eaa6 e10@posting.goo gle.com...[color=blue]
    > Hi, I'm new to the Python programming language, and eager to learn. I
    > know C and C++, but I'm sure you all know that feeling when you just
    > _need_ a new language. I chose python because I'd heard good things
    > about it. I have python 2.3 installed on my computer, and I am glad to
    > say that I've created a "Hello, World" program. Right, the only
    > problem is that the only command I've been able to figure out is
    > 'print'. That's quite a problem. I was just wondering if someone could
    > give me the command for 'cin' or 'scanf' in the C-based languages,
    > and if it is required to define variabled before using them as in the
    > C based languages (such as ;int numbofPizza' in the beginning of the
    > program). Sorry for asking such newbieish questions, but I am, in
    > fact, a newbie. Please reply to this, or email me at
    > dshaw858@hotmai l.com ... the email address I use for my newsgroups
    > (rooting_j00@ho tmail.com) isn't regularly checked because of spam...
    > meh.
    >
    > Thanks in advance,
    >
    > - Code Dark[/color]

    Presumably, you're not on a Windows machine, since the
    install packages for Windows come with the complete
    documentation.

    Go to the Python web site at www.python.org, and download
    the documentation package. Start reading at the tutorial. You can
    even do this on the web.

    John Roth


    Comment

    • Dang Griffith

      #3
      Re: New to Python; Command equivalents

      On 4 Nov 2003 23:30:01 -0800, rooting_j00@hot mail.com (Code_Dark)
      wrote:
      [color=blue]
      >Hi, I'm new to the Python programming language, and eager to learn. I
      >know C and C++, but I'm sure you all know that feeling when you just
      >_need_ a new language. I chose python because I'd heard good things
      >about it. I have python 2.3 installed on my computer, and I am glad to
      >say that I've created a "Hello, World" program. Right, the only
      >problem is that the only command I've been able to figure out is
      >'print'. That's quite a problem. I was just wondering if someone could
      >give me the command for 'cin' or 'scanf' in the C-based languages,
      >and if it is required to define variabled before using them as in the
      >C based languages (such as ;int numbofPizza' in the beginning of the
      >program). Sorry for asking such newbieish questions, but I am, in
      >fact, a newbie. Please reply to this, or email me at
      >dshaw858@hotma il.com ... the email address I use for my newsgroups
      >(rooting_j00@h otmail.com) isn't regularly checked because of spam...
      >meh.
      >
      >Thanks in advance,
      >
      >- Code Dark[/color]
      The raw_input() function is roughly equivalent to cin:[color=blue][color=green][color=darkred]
      >>> x = raw_input()[/color][/color][/color]
      Hello, world![color=blue][color=green][color=darkred]
      >>> print x[/color][/color][/color]
      Hello, world!

      raw_input() always returns string, so you will need to parse it
      according to your requirements. I usually use regular expressions if
      I'm getting arbitrary input and need to break it into parts. This is
      roughly equivalent to scanf. You can of course do "manual" string
      parsing. The split() method is useful if you just need it broken into
      separate tokens.[color=blue][color=green][color=darkred]
      >>> y = x.split(" ")
      >>> print y[/color][/color][/color]
      ['Hello,', 'world!'][color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      But John is right--reading the tutorial will probably give you more
      insight than this direct response. Good luck--I hope you also learn
      that you love Python more than C/C++.
      --dang

      Comment

      Working...