Python Forum
python indentation confusion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python indentation confusion
#1
Hi, I just started with python and I was coding in C# before and there is my biggest problem.... I am used to the {} and can't figure out how to structure if, while.... can somebody please help me?

Thanks
Reply
#2
I suggest reading python 101: https://www.blog.pythonlibrary.org/2017/...rmanently/
It's free, and it's good!
You will have fun reading and trying the code.
Reply
#3
Thanks, I will definitely check it out!!
Reply
#4
this might help
https://python-forum.io/Thread-Basic-Indentation
Recommended Tutorials:
Reply
#5
Basicaly, the indentation in Python forms a code block just like {} in the other languages. So if some code after if statement has to be executed you indent it just after the 'if':
if 5 in range(1,14):
    print('True')       # 'if' statement code block
    result = 5**5    # 'if' statement code block
    print(result)       # 'if' statement code block

print('Done!')   # out of the 'if' statement
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
Thanks everyone it really helped me a lot
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Python Shell 3.9.0 - Issue with indentation Earis 17 6,656 Oct-31-2020, 07:00 AM
Last Post: Earis
  python ast if-elif confusion holyghost 3 3,113 Apr-19-2020, 12:36 PM
Last Post: pyzyx3qwerty
  Indentation error in Python code ErnestTBass 5 3,576 Feb-28-2019, 04:26 PM
Last Post: samsonite
  Python and bash command confusion MuntyScruntfundle 0 2,059 Oct-11-2018, 04:52 PM
Last Post: MuntyScruntfundle
  python wont recognize indentation JWhykes 6 3,965 Jul-06-2018, 10:55 AM
Last Post: JWhykes
  File access confusion python windows PickyBiker 0 3,366 May-08-2017, 05:36 PM
Last Post: PickyBiker

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020