什么“<内置方法=”“lower =”“=”“str =”“object =”“at =”“[hex =”“number] =”“>”是什么意思?

时间:2016-02-10 17:15:48

标签: python built-in

这是我的代码中的第一个函数:

def start():
    decision = '0'
    while decision != '9':
        decision = input("To encode, press '1'; to decode, press '2'; and to exit, press '9'\n")
        if decision == '1':
            message = input("Input the message you want encoded.\n").lower()
            Key(message, decision)
        elif decision == '2':
            message = input("Input the message you want decoded.\n").lower()
            Key(message, decision)
        elif decision == '9':
            break
        else:
            print("Error!'"+decision+"' is an invalid input. Please make sure you type only numbers one, two and nine, NO letters!")
            start() 

    start()

为了澄清,当我输入消息时,它意味着转到另一个名为Key的函数。无论如何,当我输入信息并按回车键时,它会出现:

  

内置方法低于str对象0x0150E0D0

但是,只需删除Key(message, decision)

即可
def start():
    decision = '0'
    while decision != '9':
        decision = input("To encode, press '1'; to decode, press '2'; and to exit, press '9'\n")
        if decision == '1':
            message = input("Input the message you want encoded.\n").lower()
            print(message)
        elif decision == '2':
            message = input("Input the message you want decoded.\n").lower()
            print(message)
        elif decision == '9':
            break
        else:
            print("Error!'"+decision+"' is an invalid input. Please make sure you type only numbers one, two and nine, NO letters!")
            start()

    start()

或者即使我只写这个:

a = input("Type in a message\n").lower()
print(a)

调用函数时.lower不起作用,还是我只是愚蠢而忘记括号或什么?

更新: 这是关键功能:

def Key(message, decision):
key = input("Now, input the key which will be used to encode the message.\n".lower)
n = 0
for i in range(len(key)):
    if 64 < ord(key[n]) < 91:
        print(key[n], "is a capital letter!")
        Key()
    else:
        n = n+1
Keycode(decision, message, key)

如果有必要,我可以输入整个代码

4 个答案:

答案 0 :(得分:2)

与您最初发布的代码不同,Key包含这个有问题的行:

key = input("Now, input the key which will be used to encode the message.\n".lower)

作为输入传递给input字符串的lower方法,当您(可能)想要传递字符串然后将lower应用于input返回时

答案 1 :(得分:1)

您需要在lower之后使用一对闭括号

key = input("Input the key which will be used to encode the message.\n".lower())

答案 2 :(得分:0)

尝试将工作保存在工作空间中。如果您使用Python提示符检查结果,请使用exit()命令并再次打开Python提示符。然后尝试像以前一样调用以前的函数。

答案 3 :(得分:0)

key = input("Input the key which will be used to encode the message.\n".lower)

因为下层函数缺少括号,所以在函数调用后加上括号。所以语法就像 key = input("Input the key which will be used to encode the message.\n".lower())