首页 > 解决方案 > 设置变量时的Python语法错误

问题描述

当我尝试用等号回显一个数字时,会发生此错误:

    printThis = "=" +str(result)
            ^
SyntaxError: invalid syntax

我试图这样做print("=" +str(result)),它会出现类似的错误。

任何人都可以帮忙吗?谢谢!

编辑:

elif calc == "base":
    base = int(input('''What base would you like to use?
Available: 2 (binary) 8 (octo) 10 (decimal (normal)) 16 (hex)
Type 2, 8, 10, or 16: '''))
    if base == 2:
        result = bin(input("Type the original number: ")
        printThis = "=" +str(result)
        print(printThis)

标签: python-3.xstringsyntax

解决方案


关闭代码中以下行末尾的括号

result = bin(input("Type the original number: "))

推荐阅读