python - 定义和调用函数时出现语法错误

标签 python syntax-error

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

7年前关闭。




Improve this question




我被要求:

Write a function called start_codon which accepts a DNA sequence as its argument and returns the first codon as a string.



这是我到目前为止所拥有的:
#!/usr/bin/python

def start_codon(dna):

    codon1 = dna[0:3]
    codonstring = codon1.split(",");
    return codonstring

print (start_codon(“ATGGAACCAACGTCAGTGACTTCGTCAG”))

但是,当我按 Enter 键尝试调用该函数时,出现语法错误:
File "<stdin>", line 1
    print (start_codon(“ATGGAACCAACGTCAGTGACTTCGTCAG”))
                       ^

最佳答案

您的 string literal格式不正确。您必须使用引号 "..."或撇号 '...' :

print (start_codon("ATGGAACCAACGTCAGTGACTTCGTCAG"))
# or
print (start_codon('ATGGAACCAACGTCAGTGACTTCGTCAG'))
是 Python 无法识别的特殊字符。

关于python - 定义和调用函数时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26742093/

相关文章:

python - 兼容性问题(python 2 与 python 3)

python - 奇怪的语法错误(Python 新手)

oracle - 在plsql中运行简单游标时出错

php - PHP : syntax error help expected ;

Python:字典的分组和聚合列表[不带计数器]

python - 无法使用 python 中的 Cloudant 扩展从 CouchDb 获取 View

MySQL INSERT ... SET ... ON DUPLICATE KEY 失败...困惑

c++ - C2678 : error on insertion of Binary search tree c++

python - 如何配置 pytest 在生成测试时生成有用的名称?

python - 在 Python 中更改函数的关键字默认值