x = Flase
while !x :
a = 0
print(a)
a++
pass
if a == 10:
x = True
else:
continue
我在" a ++"时收到错误。我使用的是visual studio 2013社区,它给了我一个红色下划线" a ++"就在"通过"
答案 0 :(得分:2)
Python不支持++。你可以这样做
........
array(
'name'=>'result_severnity',
'type' => 'raw',
'value'=> '$data->getResultSevernity()',
'filter'=>$resultSevernityList,
'headerHtmlOptions'=>array('style'=>'width:300px;text-align:center;'),
....
model:
public function getResultSevernity($type="")
{
$resultSevernity = $this->result_severnity;
switch($resultSevernity)
{
case '0':
$returnText = t("common","severnity_none");
break;
case '10':
$returnText = t("common","severnity_minor");
break;
......
}
if($type=="HTML") {
$class = "severnity_".$resultSevernity;
$returnText = cHtmlTag($returnText, 'span', array('class'=>$class));
}
return $returnText;
}
答案 1 :(得分:0)
Python中没有++
或--
等语法,但您可以执行+= 1
和-= 1
。
你的程序中存在一些逻辑错误
x = False
a = 0 # a should be initialized here. If it is initialized in loop it will be a never-ending loop
while not x :
print(a)
a+=1
if a == 10:
x = True
else:
continue
备注:强>
检查您写错了False
上的拼写
不需要pass
而不是使用!
,您应该在Python中使用not
更简单,更pythonic的方式是使用for
和range
:
for a in range(10):
print(a)