缩进问题 3.7
Indentation problems 3.7
这是代码
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 notebook 变成 'break' 红色。为什么? 运行 它给出 "File "”,第 10 行
Return stop_codon_found
^
语法错误:语法无效
好吧,如果我将 'break' 向左移动一个 space,让 'break' 中的字母 b 突出并在 'break' 中与 s 中的 r 对齐'stop_codon_found',中断变为绿色。它当然会说 "unindent does not match any outer indentation level"。如果我向右打一个缩进,'break' 也会变成绿色,但它显示 'unexpected indent'
这是怎么回事?
尝试:
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
这是代码
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 notebook 变成 'break' 红色。为什么? 运行 它给出 "File "”,第 10 行 Return stop_codon_found ^ 语法错误:语法无效
好吧,如果我将 'break' 向左移动一个 space,让 'break' 中的字母 b 突出并在 'break' 中与 s 中的 r 对齐'stop_codon_found',中断变为绿色。它当然会说 "unindent does not match any outer indentation level"。如果我向右打一个缩进,'break' 也会变成绿色,但它显示 'unexpected indent'
这是怎么回事?
尝试:
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