2012-07-20 4 views
-3

저는 파이썬을 처음 사용하고 다른 언어로 된 속성을 사용했습니다. 파이썬에서 사용할 수 있습니까? 그렇다면 어떻게?파이썬 속성 ... 가능합니까?

+4

속성은 여러 가지를 의미 할 수 있습니다. 때때로 객체/클래스 멤버를 속성이라고합니다. 자바의'java.util.Properties' 클래스가 있습니다. 때로는 속성을 환경 변수라고합니다. 용어의 교차가 없도록하려는 것에 대해 자세히 설명해 주시겠습니까? – corsiKa

+0

가능한 [Python에 속성이 있습니까?] (http://stackoverflow.com/questions/813135/does-python-have-properties) – mVChr

답변

0
class SoftballRoster(object): 

    def __init__(self, first_name, last_name, team, position): 

     self._first_name = first_name 
     self._last_name = last_name 
     self._team = team 
     self._position = position 

    def first_name(self): 
     return self._first_name.capitalize() 
    first_name = property(first_name) 

    def last_name(self): 
     return self._last_name.capitalize() 
    last_name = property(last_name) 

    # another option is to use the decorator syntax: 

    @property 
    def team(self): 
     return self._team 

    @property 
    def last_name(self): 
     return self._position