Python “<位于[十六进制数字]>处的str对象的内置方法较低”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35321701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:16:58  来源:igfitidea点击:

What does "<built-in method lower of str object at [hex numbers] >" mean?

pythonbuilt-in

提问by Pezbone

This is the first function in my code:

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

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()

Just for clarification, when I input the message, it's meant to go onto another function called Key. Anyway, when I input the message and press enter it comes up with:

只是为了澄清,当我输入消息时,它的意思是转到另一个名为Key. 无论如何,当我输入消息并按回车键时,它会出现:

built-in method lower of str object at 0x0150E0D0

位于 0x0150E0D0 处的 str 对象的内置方法较低

However, it works when I simply remove the Key(message, decision)

但是,当我简单地删除 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()

Or even if I just write this:

或者即使我只是写这个:

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

Does .lowernot work when calling functions or am I just being stupid and forgetting parenthesis or something?

.lower调用函数或者我只是愚蠢和遗忘括号什么时候不工作?

UPDATE: Here is the Key function:

更新:这是关键功能:

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)

If necessary I can put in the entire code

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

采纳答案by Scott Hunter

Unlike in your originally posted code, Keycontains this problematic line:

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

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

which passes as input to inputthe lowermethod of a string, when you (presumably) want to pass the string and then apply lowerto what inputreturns.

其通过作为输入inputlower字符串的方法,当你(大概)要传递的字符串,然后应用lower到什么input回报。

回答by TheTRCG

After .upperor .lowerthere has to be a closed pair of parentheses. You can put custom arguments in them but if you just want to capitalize the input leave them empty.

之后.upper.lower必须有一对闭括号。您可以将自定义参数放入其中,但如果您只想大写输入,请将它们留空。

Example:

例子:

user=(input("Enter a letter:")).upper()

This will change case to upper. Hope it helps!

这会将大小写更改为大写。希望能帮助到你!

回答by Tiff

Try saving your work in your work space. If you're using the Python prompt to check your results, use the exit()command and open a Python prompt again. Then try calling the previous functions as you were doing earlier on.

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