0
What is code indentation?
I am having a problem. My code in python well but there is this code indentation.. I don't understand it very much. So pls help to understand it.
5 Answers
+ 1
Please donât double posting your question, you can always edit your post.
If possible, please bring the code you posted in this thread.
Back to your question, IF works independently but ELSE and ELIF work depend on IF, and ELSE / ELIF is placed at the same level as IF.
Example 1:
if 1000 > 600:
print("Yes")
# display "Yes"
Example 2:
if 600 > 1000:
print("Yes")
else:
print("No")
# display "No"
Example 3:
if 600 > 1000:
print("Yes")
else:
print("No")
# Syntax Error
+ 5
Talha Lut Salam ,
generally speaking, indentation is used to give a structure and scope of code blocks. it is used in this cases:
1. indentation is required when using:
> loops (`for ...` loop, `while ...` loop, `with ...` context manager)
> conditional statements (`if`, `elif`, `else`)
the indented lines are considered as a part of the block
2. function definition:
> the indented lines are considered as a part of the function.
3. exception handling:
> `try`, `except`, `else`, `finally`
> the indented lines are considered as part of the above mentioned blocks
3. indentation is also used for:
> classes
> nested code blocks
+ 1
You can view your post by going to "Create" > "Discuss", on the filter select "My Questions".
0
Thank you very much. I understand that.
And what you said double posting is after 4 years(personal problem) I came to sololearn again to learn . And I forget everything how sololearn works except few areas. I couldn't find my question so I had to post double. If you don't mind can you pls tell me how can I find my question which I had lost?
0
Thank you very much. And have a great day.