How to write simple "if elif else" conditional in Python


hi there

i did a simple list.append in python and it works for a define liste inside python. But when im trying to add a input for Dynamo use, it seems i had an issue.

here the code :

layer = IN[0]
for i in layer[]:
    if i == red :
    elif i == yellow:
        styles.append ("0.18mm")
    	else :
        	styles.append ("0.13mm")

OUT = styles

im sure it an noob question, but help will be appreciate.

thank you

True false switch challenge


Hi @Yien,
you don’t need to put “[]” in :
for i in layer:


thank you Mostafa

but i still have this :


those elements in your list are strings right? If the answer is yes then you should put “” in your conditional statements :

if i == "red":

and so on …


i have strings and numbers.
i just change for i == “red” : and so on…

Update Version Python conditional not working
layer = IN[0]
for i in layer:
	if i == "red" :
	elif i == "yellow":
		styles.append ("0.18mm")
	else :
		styles.append ("0.13mm")

OUT = styles
Python Nodes Basics

many thanks Mostafa!

it was indeed a noob question.

1 Like

No problem glad I could help getting you started :slight_smile:


i’ll show you later the result, the main goal is to select all line style from Autocad (which is by color or layer) and transfert them to Revit line style.

thank you again


Couple of housekeeping comments. First and foremost, please format code posted using the “```” so that its displayed properly. Secondly please write a clear and concise description in the title of the post. “Python input” is not exactly descriptive.

Thank you.


Some further knowledge for you is that you could do the following to your code so it can adapt without modification to a increased amount of checks in the future(code and image show below).


#modified by Brendan Cassidy

#loop for main input list
for i in IN[0]:
	#loop for the comparison
	for b in IN[1]:
		if i == b[0]:
	#Checks if list is empty if yes adds 0.00mm to element	
	if temp_list:
	else :

OUT = styles


Conditional evaluation of several lists in Python