Indentation question


#1

Hello,

I need clarification about indentation,
here in the Def if i choose 4 tab for the IF LEN then i use the 4 tab everywhere after that isnt ? but what about the RETURN, how many are generally use , 8 ?
thanks

def perm(l):
        # Compute the list of all permutations of l
     if len(l) <= 1:
                  return [l]

#2

there are two settings for the tab key: soft tabs and hard tabs

soft tabs are converted to spaces when the tab key is pressed, so when the editor is set to soft tab, the tab key will insert 4 spaces (or whatever its set to)

the hard tabs will insert a tab character, which takes up a number of spaces

4 spaces is most common in python. You can set your editor to insert 4 spaces when tab key is pressed, so then you get the following code:

def perm(l):
    # Compute the list of all permutations of l
    if len(l) <= 1:
        return [l]

so then return has 8 spaces total, or two tabs. So return is nested inside the if clause

seems you have 12 spaces (3 tabs) in total, that is a bit much.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.