"做"作为关键字 [英] "do" as a keyword

查看:132
本文介绍了"做"作为关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说我非常喜欢使用Python。我是第3名学生,并且已经使用python 3个月了(感谢

trac!)。我不认为自己是一个经验丰富或聪明的程序员,

但我能够顺利通过。


我喜欢Python的东西几乎就是你所做的一切可以用伪代码编写的
然后传入Python,而不会产生很大的差价。


但是通读疣和阅读缺乏做什么时候

陈述我也开始思考做某事,如果

''真''其他''做'这个'',并思考是否可能这句话可以

使用关键字do的包含。


它会清除这种语句的用法,因为它会愉快地读取
。或者我是从蚂蚁山上建造一座山?

First off let me state that I really enjoy using Python. I am a 3rd
year student and have been using python for 3 months, (thanks to
trac!). I do not consider myself an experienced or clever programmer,
but I am able to get by.

Something I love about Python is that almost everything you do can be
written in pseudo code then carried across into Python without a great-
deal of difference.

But reading through the warts and reading about a lack of "do while
statements" I also started to ponder about the "''do something'' if
''true'' else ''do this''", and pondered if perhaps this statement could
do with the including of the keyword do.

It would clear up the usage of such a statement because it would read
happily. Or am I making a mountain out of an ant hill?

推荐答案

co ********* @ gmail.com 写道:
co*********@gmail.com wrote:

首先让我说我真的喜欢使用Python。我是第3名学生,并且已经使用python 3个月了(感谢

trac!)。我不认为自己是一个经验丰富或聪明的程序员,

但我能够顺利通过。


我喜欢Python的东西几乎就是你所做的一切可以用伪代码编写的
然后传入Python,而不会产生很大的差价。


但是通读疣和阅读缺乏做什么时候

陈述我也开始思考做某事,如果

''真''其他''做'这个'',并思考是否可能这句话可以

使用关键字do的包含。


它会清除这种语句的用法,因为它会愉快地读取
。或者我是从蚂蚁山上建造一座山?
First off let me state that I really enjoy using Python. I am a 3rd
year student and have been using python for 3 months, (thanks to
trac!). I do not consider myself an experienced or clever programmer,
but I am able to get by.

Something I love about Python is that almost everything you do can be
written in pseudo code then carried across into Python without a great-
deal of difference.

But reading through the warts and reading about a lack of "do while
statements" I also started to ponder about the "''do something'' if
''true'' else ''do this''", and pondered if perhaps this statement could
do with the including of the keyword do.

It would clear up the usage of such a statement because it would read
happily. Or am I making a mountain out of an ant hill?



我怀疑这会获得任何牵引力。之前已经提出了类似的建议

- 例如 http://www.python.org/dev/peps/pep -0315 /


但他们没有


您可以使用一些技巧来模拟所需的行为没有

会破坏眼睛。例如

而True:

do_something()

如果条件:休息


授予,


do

do_something()(

条件


多一点愉快 - 但还不足以改变我会说的语言。


Diez

I doubt this will gain any traction. Similar proposals have been made
before - e.g. http://www.python.org/dev/peps/pep-0315/

But they didn''t

There are a few tricks you can use to emulate the desired behavior without
being to disruptive to the eye. E.g.
while True:
do_something()
if condition: break

Granted,

do
do_something()(
while condition

is a bit more pleasant - but not enough to change the language I''d say.

Diez


2007-12-11, co*********@gmail.com < co ****** ***@gmail.com写道:
On 2007-12-11, co*********@gmail.com <co*********@gmail.comwrote:

首先让我说我非常喜欢使用Python。我是一个

三年级学生并且已经使用3个月的python,

(感谢trac!)。我不认为自己是一个经验丰富的或者b $ b聪明的程序员,但我能够通过。


我喜欢Python的一点是你几乎所做的一切

都可以用伪代码编写然后传入Python中

没有太大的区别。


但请仔细阅读疣和阅读缺乏做什么/ b $ b而语句我也开始思考'做'

某事''如果''是''其他''做这个'',并思考是否

这个陈述可以用关键字do的包含来做。


它会清除这种陈述的用法,因为它会很愉快地读取
。或者我是用蚂蚁在b $ b山上建造一座山吗?
First off let me state that I really enjoy using Python. I am a
3rd year student and have been using python for 3 months,
(thanks to trac!). I do not consider myself an experienced or
clever programmer, but I am able to get by.

Something I love about Python is that almost everything you do
can be written in pseudo code then carried across into Python
without a great- deal of difference.

But reading through the warts and reading about a lack of "do
while statements" I also started to ponder about the "''do
something'' if ''true'' else ''do this''", and pondered if perhaps
this statement could do with the including of the keyword do.

It would clear up the usage of such a statement because it
would read happily. Or am I making a mountain out of an ant
hill?



当我使用提供do-while或do-until循环的语言

构造时我很少需要它们。


我个人怀念


for init;条件;接下来:


比do-while更多,但是结构化的for循环不适合在
Python中,因为init和next会(可能)必须是声明

(或语句套件)而不是表达式。因此,很好的迭代器和生成器的创新,否则可能是
没有找到Python的家。我想知道在迭代器之前有什么编程Python

就好了。


但是,你是否特别需要一个do-while构造?

也许我们可以告诉你其他选择。


-

Neil Cerutti

When I use languages that supply do-while or do-until looping
constructs I rarely need them.

I personally miss

for init; condition; next:

more than do-while, but the structured for loop doesn''t fit in
Python since init and next would (probably) have to be statements
(or statement suites) rather than expressions. Hence, the cool
innovations of iterators and generators, which otherwise might
not have found a home in Python. I wonder what programming Python
was like before iterators sometimes.

However, did you have an specific need for a do-while construct?
Perhaps we could show you the alternatives.

--
Neil Cerutti


我也开始思考''
I also started to ponder about the "''do

something''if''true''else''do this'',并思考如果可能

这个声明可以用关键字do的包含。
something'' if ''true'' else ''do this''", and pondered if perhaps
this statement could do with the including of the keyword do.



Python在版本> = 2.5中支持此功能:

Python has support for this in versions >= 2.5:


>> a =范围(0,5)
b =范围(5,8)
min(a)如果sum(a)< sum(b)else min(b)
>>a = range(0, 5)
b = range(5, 8)
min(a) if sum(a) < sum(b) else min(b)



0


在以前的版本中,你可以使用和/或技巧:

0

In prior versions, you can use the and/or trick:


>>(sum(a) < sum(b)和[min(a)]或[min(b)])[0]
>>(sum(a) < sum(b) and [min(a)] or [min(b)])[0]



0


-Tor Erik

0

-Tor Erik


这篇关于&QUOT;做&QUOT;作为关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆