python学习-- class 类中需要注意的地方

2023-06-05,,

from django.db import models

class Person(models.Model):
    name = models.CharField(max_length=30)
    age = models.IntegerField()
 

name 和 age 等字段中不能有 __(双下划线,因为在Django QuerySet API中有特殊含义(用于关系,包含,不区分大小写,以什么开头或结尾,日期的大于小于,正则等)

也不能有Python中的关键字,name 是合法的,student_name 也合法,但是student__name不合法,try, class, continue 也不合法,因为它是Python的关键字( import keyword; print(keyword.kwlist) 可以打出所有的关键字)

python学习-- class 类中需要注意地方的相关教程结束。

《python学习-- class 类中需要注意的地方.doc》

下载本文的Word格式文档,以方便收藏与打印。