python - Assign a variable value in an if or while statement -



python - Assign a variable value in an if or while statement -

possible duplicate: is there way variable assignments straight within while(<here>) loop in python?

sorry such basic question. i'm trying larn python, haven't found reply this.

in python, can assign value variable in while or if statement? if so, how?

for example. had this:

line_list = [] while true: line = raw_input(">>> ") if not line: break line_list.append(line) print line_list

but i'd this:

line_list = [] while line = raw_input(">>> "): line_list.append(line) print line_list

the tutorials i'm looking @ don't mention 1 way or another, mutual build in other languages.

as frédéric's reply indicates, impossible assign variable while or if, can accomplish same thing using iter() function/sentinel phone call format:

for line in iter(lambda: raw_input(">>>"), ""): line_list.append(line)

python while-loop

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -