0
Confusion in "nested if" in Python
how does actually nested if work in Python. In this following code , 1st and 3rd if statements are true. so I get two output as expected. https://code.sololearn.com/cT9SwUJ1rV3O/?ref=app but if I put a TAB before 3rd "if" , it becomes part of the second"if". In C or Java we use braces to make nested "if". so I'm finding Python "nested if" a bit confusing. Thanks in advance.
3 odpowiedzi
+ 1
It works based on indentation. It is 4 spaces or a tab.
+ 1
Unlike most other programming languages, white space in python matters, and essentially replaces curly brackets. While in other languages you could write the something like:
static void myFunction()
{
// Good looking code;
}
as:
static void
myFunc( ){
// Don't write code like this! This is confusing to look at;
}
In python, this would not work. Instead of curly brackets, python uses indention.
0
got it :)
thanks to both of you