#Collecting parameters
def print_parm(*arg,**named_arg):
print(arg,"---",named_arg)
print_parm(1)
print_parm(1,2)
print_parm([1,2,3,4])
print_parm(*[1,2,3,4])
print_parm((1,2,3,4))
print_parm(*(1,2,3,4))
print_parm({"a":1,"b":2,"c":3})
print_parm(**{"a":1,"b":2,"c":3})
print_parm(1,2,3,{"a":1,"b":2,"c":3})
print_parm(1,2,3,a=1,b=2,c=3)
#class
class sample:
def __double_underscore_would_be_renamed_should_not_access(self):
print ("should not be access directly")
def access(self):
print("access first")
self.__double_underscore_would_be_renamed_should_not_access()
def _single_underscore_method_would_not_be_imported(self):
print("I will not be imported")
x=sample()
x.access()
#you can't call x.__double_underscore_would_be_renamed_should_not_access() directly
#but you can...
x._sample__double_underscore_would_be_renamed_should_not_access()
2008年12月8日 星期一
Begining Python: From Novice to Professional - 2
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言