python namespace

x = 11     				#global 
def f():
	print x				#global

def g():
	x = 22				#local
	print x


class c:
	x = 33				# class attribute
	def m(self):	
		x = 44			#local variable
		self.x = 55 	#instance attribute


if __name__ == '__main__':
	print x       		#global
	f()					#global
	g()					#local 22
	print x				#global 11

	print c.x	 		#class attribute 33

	obj = c()
	print obj.x	 		# class name inhrited by instance 33
	obj.m()				# attach attribute name x to instance now 55
	print obj.x	 		# 55 now instance

	print c.x	 		# class attribute 33
posted @ 2017-04-26 13:39  zeroArn  阅读(189)  评论(0编辑  收藏  举报