FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python/property.py at master · Idris-RAD/learn-python · GitHub
Idris-RAD
/
learn-python
Public
forked from
tanteng/learn-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python
/
property.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
19 lines (16 loc) · 430 Bytes
Breadcrumbs
learn-python
/
property.py
Copy path
File metadata and controls
19 lines (16 loc) · 430 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# -*- coding: utf-8 -*-
# 属性装饰器
class
Student
(
object
):
@
property
def
score
(
self
):
return
self
.
_score
@
score
.
setter
def
score
(
self
,
value
):
if
not
isinstance
(
value
,
int
):
raise
ValueError
(
'必须输入数字!'
)
if
value
<
0
or
value
>
100
:
raise
ValueError
(
'必须大于0小于100!'
)
self
.
_score
=
value
s
=
Student
()
s
.
score
=
101
print
(
s
.
score
)
Back
|
FazBrowse Home
|
New Git URL