473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Doubt

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
8 1171
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
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
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
ജഗന്നാഥ് 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
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
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
>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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: NagaKiran | last post by:
Hi I want to post doubts in VB. Where can I post my doubts? thanks bye
77
by: muttaa | last post by:
Hello all, My doubt is going to be so primitive that i ask you all to forgive me beforehand.... Here's the code snippet: int main() { int x=5;
11
by: Bob Nelson | last post by:
I don't remember seeing the term ``doubt'' used much in c.l.c. back in the 90's. When did this word become nearly synonymous with ``question'' or ``query'' and does it have static duration?
122
by: ivan | last post by:
hi all, if I have: if(A && B || C) which operation gets executed first? If I remeber well should be &&, am I correct? thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.