What is the main difference between class and def in python? Can a class in python interact with django UI (buttons)?
解决方案
class is used to define a class (a template from which you can instantiate objects).
def is used to define a function or a method. A method is like a function that belongs to a class.
# function
def double(x):
return x * 2
# class
class MyClass(object):
# method
def myMethod(self):
print ("Hello, World")
myObject = MyClass()
myObject.myMethod() # will print "Hello, World"
print(double(5)) # will print 10
No idea about the Django part of your question sorry. Perhaps it should be a separate question?