简体   繁体   中英

Having issues with unindent error in python

  def linear_probe(self, value, start_index):
    hashed_key = start_index % len(self.table)
    while self.table[hashed_key] is not None:
      hashed_key = (hashed_key + 1) % len(self.table)
    return hashed_key, value`enter code here`

Hi here is my code for linear_probe function that I'm using in a lab, however for some reason I keep getting the unindent does not match any outer indentation level. however from how I can see my tabbing looks good as well as there are no white spaces

You are most likely mixing tabs and spaces.

Please make sure your editor is always using spaces.

If possible, let your editor highlight tabs.

The code as posted has a 2-space indentation for the whole function. Remove 2 spaces from the front of each line and try again:

## <-- accidental indent?
  def linear_probe(self, value, start_index):
    hashed_key = start_index % len(self.table)
    while self.table[hashed_key] is not None:
      hashed_key = (hashed_key + 1) % len(self.table)
    return hashed_key, value`enter code here`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM