ORM对象关系映射:用于实现面向对象编程语言里不同类型系统的数据中间的转换(就是用面向对象的方式去操作数据库的创建表以及增删改查等操作)
==================================
1.__str__方法:当打印对象的时候,不打印一堆内存地址(为了直观的让我们知道对象是谁)
class person():
def __init__(self,name):
self.name=name
class person():
def __init__(self,name):
self.name=name
obj=person('star')
print(obj)
#运行结果:
<__main__.person object at 0x0000013036B8B4E0>
__str__:
x
from django.test import TestCase
print(obj)
#运行结果:
<__main__.person object at 0x0000013036B8B4E0>
__str__:
x
from django.test import TestCase
# Create your tests here.
class person():
def __init__(self,name):
self.name=name
class person():
def __init__(self,name):
self.name=name
def __str__(self):
return self.name
return self.name
obj=person('star')
print(obj)# <__main__.person object at 0x00000212E1FAB4E0>
#==========================
print(obj)# <__main__.person object at 0x00000212E1FAB4E0>
#==========================
# Create your tests here.
class person():
def __init__(self,name):
self.name=name
class person():
def __init__(self,name):
self.name=name
def __str__(self):
return self.name
obj=person('star')
print(obj)# star
#============================
return self.name
obj=person('star')
print(obj)# star
#============================