예제 #1
0
from c1 import Student

student = Student('afs', 2)
student.print_file()
student.do_homework()
예제 #2
0
from c1 import Student

s1 = Student("Tinywan", 24)
s2 = Student("TinyAiAI", 22)

print(s1.name)
print(s2.name)
print(Student.name)
# print(s1.__dict__)
# print(Student.__dict__)
예제 #3
0
파일: c4.py 프로젝트: leeylong/pystudy
"""  """
from c1 import Student


#实例化
student = Student('tony','男',18)
print(student.print_file())
#由此可见__init__方法在实例化对象执行时可以自动调用构造函数,并且可以被显示调用
예제 #4
0
from c1 import Student

student = Student()
student.print_file()
예제 #5
0
from c1 import Student

zhangsan = Student()
zhangsan.print_file()
예제 #6
0
파일: c2.py 프로젝트: ptkang/python-primary
'''
@Author: your name
@Date: 2019-11-26 22:52:00
@LastEditTime: 2019-11-26 22:53:09
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \python\vscode\class\c2.py
'''
from c1 import Student

student = Student('Justin', 35, '男')
student.print_student_doc()
예제 #7
0
from c1 import Student
stu = Student()
stu.print_file()
예제 #8
0
파일: c2.py 프로젝트: ShenlinWei/Learn
from c1 import Student

s = Student()
s.print_file()
예제 #9
0
파일: c2.py 프로젝트: jiangjun0130/py-demo
from c1 import Student

student = Student('JJ', 18)
#student.do_homework()
Student.plus_sum()
student.plus_sum()
# 如果在构造函数中,没有对属性进行初始化,并且当属性有默认值时,如果在【实例方法】调用中,没有获取到变量值时,则会到类作用域中获取对应的属性值。
# 如果是在【类方法】中,则不会到类作用域中获取对应的属性值。
print(student.name)

#print(student.__dict__)
#print(Student.__dict__)

#Student.add(1,2)

student.marking(59)

# 在这里能设置__score,不是因为设置的私有属性没有生效。而是因为Python是动态语言的特性,在这里时实际上是给student实例,新增了一个__score实例变量
student.__score = -1
print(student.__score)
# {'name': 'JJ', 'age': 18, '_Student__score': 59, '__score': -1}
# 从上面可以分析出:Python会把私有变量重新命名为:_[类名][变量名]。所以在以申明的名称访问时,会报错。
print(student.__dict__)

# 验证上述说明:会进行报错。'Student' object has no attribute '__score'
#student2 = Student('Tim',18)
#print(student2.__score)
예제 #10
0
from c1 import Student

student1 = Student('hh', 18)
student1.marking(-1)
# student2 = Student('dasd', 19)
# print(student.name)
예제 #11
0
파일: c2.py 프로젝트: huiup/python_notes
from c1 import Student

student1 = Student('zhang',23)
student1.do_homework()