function return None after execution of a function
Question:
I have this code to split a DNA strand into groups of 3. Everything in the result is intended except for that last "None"
def codons(x):
for i in range(0, len(x), 3):
result = print(x[i:i + 3])
return result
When using with
print(codons('ATGCTCAAGTAGR'))
Returns:
ATG
CTC
AAG
TAG
R
None
Answers:
Everything is right, just get rid of the return and the print when calling the function.
def codons(x):
for i in range(0, len(x), 3):
print(x[i:i + 3])
codons('ATGCTCAAGTAGR')
You can save the result in a list
def codons(x):
result=[]
for i in range(0, len(x), 3):
result.append(x[i:i + 3])
return result
I have this code to split a DNA strand into groups of 3. Everything in the result is intended except for that last "None"
def codons(x):
for i in range(0, len(x), 3):
result = print(x[i:i + 3])
return result
When using with
print(codons('ATGCTCAAGTAGR'))
Returns:
ATG
CTC
AAG
TAG
R
None
Everything is right, just get rid of the return and the print when calling the function.
def codons(x):
for i in range(0, len(x), 3):
print(x[i:i + 3])
codons('ATGCTCAAGTAGR')
You can save the result in a list
def codons(x):
result=[]
for i in range(0, len(x), 3):
result.append(x[i:i + 3])
return result