一份陈述中的作业和比较 [英] Assignment and comparison in one statement

查看:94
本文介绍了一份陈述中的作业和比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello group,


我刚刚开始使用Python而且我对它非常缺乏经验,所以

远。拥有强大的C / C ++背景,我希望做一些像


if(q = getchar()){

printf("%d \\ \\ n",q);

}


或翻译成Python:


if(p = myfunction ()):

打印p


但是,这个赋值和比较不管用。什么是

" Python方式"做这种事情?


非常感谢,

Johannes


-

" Wer etwas kritisiert muss es noch lange nicht selber besser k?nnen。 Es

reicht zu wissen,da? andere es besser k?nnen und andere es auch

besser machen um einen Vergleich zu bringen。 - Wolfgang Gerber

in de.sci.electronics< 47 *********************** @ news.freenet.de>

Hello group,

I''m just starting with Python and am extremely unexperienced with it so
far. Having a strong C/C++ background, I wish to do something like

if (q = getchar()) {
printf("%d\n", q);
}

or translated to Python:

if (p = myfunction()):
print p

However, this "assignment and comparison" is not working. What''s the
"Python way" of doing this kind of thing?

Thanks a lot,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser k?nnen. Es
reicht zu wissen, da? andere es besser k?nnen und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electronics <47***********************@news.freenet.de>

推荐答案

5月23日下午6:59,Johannes Bauer< dfnsonfsdu ... @ gmx.dewrote:
On May 23, 6:59 pm, Johannes Bauer <dfnsonfsdu...@gmx.dewrote:

你好组,


我刚开始使用Python而且我对它非常缺乏经验,所以

远。拥有强大的C / C ++背景,我希望做一些像


if(q = getchar()){

printf("%d \\ \\ n",q);


}


或翻译成Python:


if (p = myfunction()):

print p


但是,这个赋值和比较不管用。什么是

" Python方式"做这种事情?
Hello group,

I''m just starting with Python and am extremely unexperienced with it so
far. Having a strong C/C++ background, I wish to do something like

if (q = getchar()) {
printf("%d\n", q);

}

or translated to Python:

if (p = myfunction()):
print p

However, this "assignment and comparison" is not working. What''s the
"Python way" of doing this kind of thing?



p = myfunction()

如果p:

打印p


(我也推荐在C语言中这样做。)


如果您想在elif子句中执行此操作,请查找

最近的线程C-like赋值表达式?列出了一些

的解决方法。或者只是谷歌这个新闻组的赋值

表达式。这是Python中为数不多的令人烦恼的事情之一

语法。

Carl Banks


p = myfunction()
if p:
print p

(I recommend doing it this way in C, too.)

For the case where you want to do this in an elif-clause, look for the
recent thread "C-like assignment expression?" which list some
workarounds. Or just Google this newsgroup for "assignment
expression". It''s one of few minor irritating things in Python
syntax.
Carl Banks


5月23日,6:59 * pm,Johannes Bauer< dfnsonfsdu ... @ gmx.dewrote:
On May 23, 6:59*pm, Johannes Bauer <dfnsonfsdu...@gmx.dewrote:

Hello group,


我刚刚开始使用Python而且对它非常缺乏经验,所以

远。拥有强大的C / C ++背景,我希望做一些像


if(q = getchar()){

* * * * printf(" ;%d \ n",q);


}


或翻译成Python:


if(p = myfunction()):

* * * * print p


但是,这个赋值和比较不管用。什么是

" Python方式"做这种事情?
Hello group,

I''m just starting with Python and am extremely unexperienced with it so
far. Having a strong C/C++ background, I wish to do something like

if (q = getchar()) {
* * * * printf("%d\n", q);

}

or translated to Python:

if (p = myfunction()):
* * * * print p

However, this "assignment and comparison" is not working. What''s the
"Python way" of doing this kind of thing?



当然最明显和可读:使用两个语句,因为一个

应该做什么而不管语言,而不是诉诸错误 -

容易入侵。


George

The most obvious and readable of course: use two statements, as one
should do regardless of the language, instead of resorting to error-
prone hacks.

George


06:59,sabato 24 maggio 2008 Johannes Bauer写道:
On 06:59, sabato 24 maggio 2008 Johannes Bauer wrote:

但是,这个赋值和比较不管用。什么是

" Python方式"做这种事情?
However, this "assignment and comparison" is not working. What''s the
"Python way" of doing this kind of thing?



如果你想说一种不被理解的语言,你将会面对

意想不到的结果。

当你开始使用C / C ++时,你是用简单的英语写作

程序吗?

远离火焰,每种语言都有自己的语法有一段时间它需要学习b $ b。

因此,即使我自己仍然不好写英语,因为我的思维思考

意大利语句子。

If you want speak a language that isn''t understood mostly you''ll face
unexpected risults.
When you got started with C/C++, were you writing plain english to do
programs?
Far away to be a flame, each language have its own grammar that some time it
will need to be learnt.
Therefore, even myself still bad to write english, since my mind thinking
italian sentences.


这篇关于一份陈述中的作业和比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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