Booleans values at funtions in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Booleans values at funtions in Python

I'm trying to write a code that supposes a online buying; it takes the user information and confirm if it is ok. I wrote a function that confirm if each data is correct with a boolean value, the problem is that the boolean value (defined as False out of the function) only changes inside the function, then it returns to the initial value (False). I tried with "return" after change the value, how I can change it inside the function without it returns to the initial value? (Sorry for my English, I'm still studying) Estoy intentando escribir un c贸digo que supone una compra en l铆nea; toma la informaci贸n del usuario y confirma si es correcto. Escrib铆 una funci贸n que confirma si es correcto cada dato con un valor booleano (booleans), el problema es que el valor booleano (definido como Falso fuera de la funci贸n) solo cambia dentro de la funci贸n, despu茅s vuelve al valor inicial (Falso). Intent茅 con "return" despu茅s cambiar el valor, 驴c贸mo puedo cambiarlo dentro de la funci贸n si que regrese al valor inicial?

16th Dec 2020, 2:40 AM
J R - avatar
1 Answer
+ 2
Add the global keyword to the start of the function followed by the variables you want use in the function..
16th Dec 2020, 2:53 AM
Steve Sajeev
Steve Sajeev - avatar