缩进问题3.7

问题描述 投票:0回答:1

这里是代码

def has_stop(dna,frame) :
   stop_codon_found=False
   stop_codons =['tga','tag','taa']
   for i in range(frame,len(dna),3) : 
      codon =dna[i:i+3].lower()
      if codon in stop_codons:
         stop_codon_found=True
         break
   Return stop_codon_found

Python Jupyter笔记本在RED中变成'break'。为什么?并运行它会得到“文件”,第10行返回stop_codon_found^SyntaxError:语法无效

[好吧,如果我将'break'向左移动一个空格,使'break'中的字母b突出并在'break'中使r与'stop_codon_found'中的s对齐,则break变成绿色。当然,它说“不缩进不匹配任何外部缩进级别”。如果我在右边打了一个缩进,“ break”也会变成绿色,但是它说“意外缩进”

发生了什么事?

python jupyter-notebook indentation definition
1个回答
1
投票

尝试:

def has_stop(dna,frame) :
   stop_codon_found=False
   stop_codons =['tga','tag','taa']
   for i in range(frame,len(dna),3) : 
      codon =dna[i:i+3].lower()
      if codon in stop_codons:
         stop_codon_found=True
         break
   return stop_codon_found

为了使return包含在功能中,必须在def ...下设置一个缩进级别。也是return而不是Return

© www.soinside.com 2019 - 2024. All rights reserved.