Can';t分配给函数调用(python 3)
当我运行此功能时,它会显示无法分配功能,如何解决此问题?此块是问题所在Can';t分配给函数调用(python 3),python,Python,当我运行此功能时,它会显示无法分配功能,如何解决此问题?此块是问题所在 print ("** ** ***") print ("** ** ***") print ("********* ***") print ("** ** ***") print ("** ** ***") Contacts = [0] if Contacts == [0]: print ("You have no friends!")
print ("** ** ***")
print ("** ** ***")
print ("********* ***")
print ("** ** ***")
print ("** ** ***")
Contacts = [0]
if Contacts == [0]:
print ("You have no friends!")
from time import sleep
Contact = input("Would you like to add a contact: Y or N?")
if Contact == "Y":
for c in range(0,1):
print (1 - c)
sleep(1)
Contact = input("Name:")
Contacts.append(Contact)
Contact1 = input ("age:")
Contacts.append(Contact1)
Contact2 = input ("Location:")
Contacts.append(Contact2)
Contact3 = input ("Phone Number:")
Contacts.append(Contact3)
Contactsn = open("Contactsn.txt", "w")
Contactsn.write(Contact)
Contactsn.write(Contact1)
Contactsn.write(Contact2)
Contactsn.write(Contact3)
print (Contact)
print (Contact1)
print (Contact2)
print (Contact3)
Contactsn.close()
Contact = input("Would you like to see your Contacts:Y or N?")
if Contact == "Y":
Contactsn()
else:
Contact = input("Would you like to see your Contacts:Y or N?")
if Contact == "Y":
Contactsn()
def Contactsn():
Contactsn() = open("Contactsn.txt", "r")
print (Contactsn.read())
quit
您正在尝试将
open
的结果分配给调用函数contactsn()
的结果?要么是()
是一个输入错误,您将要用一个同名变量来隐藏函数名,要么您正在尝试一些非常奇怪的递归奇怪现象。Contactsn
()
=open(“Contactsn.txt”,“r”)
(一般来说,隐藏函数名并不理想)…那么我应该更改函数名吗?这将是一个开始,而且我假设此行的内容应该是Contactsn=open(“Contactsn.txt”,“r”)
,因此我更改了函数名和变量名以及def Contactsn():Contactsn()=open(“Coontactsn.txt”,“r”)print(Contactsn.read())退出Hanks!!我把()
def Contactsn():
Contactsn() = open("Contactsn.txt", "r")
print (Contactsn.read())