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

Doubt

P: n/a
Friends

I am a Perl programmer new to Python. I have a small doubt.
How to convert the perl notation
$a = ""; expression in Python ?

How to represent the loop
for ($a = $b; $a<=$c;$a++){
} in Python

Jagan
Linguist
Jul 23 '08 #1
Share this Question
Share on Google+
8 Replies

P: n/a
On Wed, Jul 23, 2008 at 11:51 AM, ജഗന്നാഥ് <ja*******@gmail.comwrote:
Friends

I am a Perl programmer new to Python. I have a small doubt.
How to convert the perl notation
$a = ""; expression in Python ?
a = ""
>
How to represent the loop
for ($a = $b; $a<=$c;$a++){
} in Python
for a in range(b, c + 1): pass
Jagan
Linguist
--
http://mail.python.org/mailman/listinfo/python-list


--
-- Guilherme H. Polo Goncalves
Jul 23 '08 #2

P: n/a
On Jul 23, 7:51*am, ജഗന്നാഥ് <jagana...@gmail.comwrote:
Friends

I am a Perl programmer new to Python. I have a small doubt.
How to convert the perl notation
$a = ""; expression in Python ?

How to represent the loop
for ($a = $b; $a<=$c;$a++){

} in Python

Jagan
Linguist
On most occasions you don't need to use the incrementing loop
behavior. Lists are the main data structure comparable to an array,
and you can iterate over them without using a counter. If you have:

aList = [1, 2, 3]

you can do

for item in aList:
print item
Hope this helps.

~Sean
Jul 23 '08 #3

P: n/a
On Jul 23, 3:51*pm, ജഗന്നാഥ് <jagana...@gmail.comwrote:
Friends

I am a Perl programmer new to Python. I have a small doubt.
How to convert the perl notation
$a = ""; expression in Python ?

How to represent the loop
for ($a = $b; $a<=$c;$a++){

} in Python

Jagan
Linguist
This might help you generally:
http://wiki.python.org/moin/PerlPhrasebook

- Paddy.
Jul 23 '08 #4

P: n/a
ജഗന്നാഥ് wrote:
I am a Perl programmer new to Python. I have a small doubt.
I suspect you mean "question", not "doubt". It's not quite the same thing.
How to convert the perl notation
$a = ""; expression in Python ?

How to represent the loop
for ($a = $b; $a<=$c;$a++){
} in Python
Start here:

http://www.lucasmanual.com/mywiki/PerlPythonPhrasebook

and then read either of these (preferably both):

http://www.swaroopch.com/byteofpython/
http://docs.python.org/tut/

</F>

Jul 23 '08 #5

P: n/a
On Jul 24, 1:13 am, Fredrik Lundh <fred...@pythonware.comwrote:
ജഗന്നാഥ് wrote:
I am a Perl programmer new to Python. I have a small doubt.

I suspect you mean "question", not "doubt". It's not quite the same thing.
How to convert the perl notation
$a = ""; expression in Python ?
Thank you for all to giving suggestions .

With regards

Jaganadh G

How to represent the loop
for ($a = $b; $a<=$c;$a++){
} in Python

Start here:

http://www.lucasmanual.com/mywiki/PerlPythonPhrasebook

and then read either of these (preferably both):

http://www.swaroopch.com/byteofpython/
http://docs.python.org/tut/

</F>
Jul 24 '08 #6

P: n/a
Fredrik Lundh wrote:
ജഗന്നാഥ് wrote:
>I am a Perl programmer new to Python. I have a small doubt.

I suspect you mean "question", not "doubt". It's not quite the same
thing.
It seems to be an Indian/Asian thing. By now, I tuned myself to read "doubt"
as "question/problem"...

Diez
Jul 24 '08 #7

P: n/a
>How to convert the perl notation
$a = ""; expression in Python ?
a = ""
>How to represent the loop
for ($a = $b; $a<=$c;$a++){

} in Python
for a in range(b, c + 1):
do_something()
** Posted from http://www.teranews.com **
Jul 24 '08 #8

P: n/a
You wrote:
How to represent the loop
for ($a = $b; $a<=$c;$a++){
} in Python
As other pointed out, iterating through a list or range is often a far
more elegant way to do a loop than a C-style loop. But the C-style for
loop is just syntactic sugar for a while loop. In some cases, C-style
for loops can have an initializer, a set of conditions, and incrementer
parts that are all based on different variables. For example:

for (a=begin_func() ; x < 3 and sometest(b) ; i=somefunc() )

This highly illogical and contrived function could not be represented in
python with a simple "for x in blah" statement. Rather you have to
represent it in its true form, which is a while loop:

a=begin_func()
while x < 3 and sometest(b):
#do stuff
#loop body
i=somefunc()
In fact, the perl/c for loop of the form:

for (<initializer>;<condition>;<incrementer>)

always translates directly to:

<initializer>
while <condition>:
#loop body

<incrementer>
Jul 25 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.