New to Python; Command equivalents

C

Code_Dark

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
(e-mail address removed) ... the email address I use for my newsgroups
([email protected]) isn't regularly checked because of spam...
meh.

Thanks in advance,

- Code Dark
 
J

John Roth

Code_Dark said:
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
(e-mail address removed) ... the email address I use for my newsgroups
([email protected]) isn't regularly checked because of spam...
meh.

Thanks in advance,

- Code Dark

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
 
D

Dang Griffith

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
(e-mail address removed) ... the email address I use for my newsgroups
([email protected]) isn't regularly checked because of spam...
meh.

Thanks in advance,

- Code Dark
The raw_input() function is roughly equivalent to cin: 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.
>>> y = x.split(" ")
>>> print y ['Hello,', 'world!']
>>>

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top