数据库课程设计python简单的
时间: 2023-12-20 09:32:03 浏览: 29
```python
# 以下是一个简单的Python数据库课程设计示例,用于创建一个简约高效的博客系统。
# 创建文章类
class Article:
def __init__(self, title, content, category, tags):
self.title = title
self.content = content
self.category = category
self.tags = tags
# 创建博客系统类
class BlogSystem:
def __init__(self):
self.articles = []
def create_article(self, title, content, category, tags):
article = Article(title, content, category, tags)
self.articles.append(article)
def get_public_articles(self):
public_articles = [article for article in self.articles if 'public' in article.tags]
return public_articles
# 使用示例
blog = BlogSystem()
blog.create_article("Python Basics", "An introduction to Python programming.", "Programming", ["python", "public"])
blog.create_article("Data Analysis", "Using Python for data analysis.", "Data Science", ["python", "data", "public"])
public_articles = blog.get_public_articles()
for article in public_articles:
print(f"Title: {article.title}, Category: {article.category}, Tags: {article.tags}")
```