2.定义一个学生类Student,属性有age(年纪),name(姓名),score(分数),实例化6个对象,放在集合中,有如下Student 对象
时间: 2024-04-10 10:34:04 浏览: 122
Sure, here's an example of how you can define a Student class in Python:
```python
class Student:
def __init__(self, name, age, score):
self.name = name
self.age = age
self.score = score
```
To create 6 Student objects and store them in a collection, you can do the following:
```python
students = []
# Create and add Student objects to the collection
student1 = Student("John", 18, 85)
students.append(student1)
student2 = Student("Emily", 17, 92)
students.append(student2)
student3 = Student("Michael", 19, 78)
students.append(student3)
student4 = Student("Sarah", 20, 90)
students.append(student4)
student5 = Student("David", 18, 88)
students.append(student5)
student6 = Student("Emma", 17, 95)
students.append(student6)
```
Now, you have 6 Student objects stored in the `students` collection. Each object has attributes like `name`, `age`, and `score` that you can access and manipulate as needed.
阅读全文
相关推荐
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)