Ejemplo n.º 1
0
mystuff.apple()
print mystuff.tangerine

mystuff['apple'] # get apple from dict
mystuff.apple() # get apple from the module
mystuff.tangerine # same thing, it's just a variable

class MyStuff(object):
	def _init_(self):
		self.tangerine = "And now a thousand years between"

	def apple(self):
		print "I AM CLASSY APPLES!"

# Instaniates the class MyStuff
thing = MyStuff()
thing.apple()
print thing.tangerine

# dict style
mystuff['apples']

#module style
mystuff.apples()
print mystuff.tangerine

#class style
thing = MyStuff()
thing.apples()
print thing.tangerine
Ejemplo n.º 2
0
# this is just a variable
tangerine = "Living reflection of a dream"

import mystuff
mystuff.apple()
print(mystuff.tangerine)

mystuff['apple']  # get apple from dict
mystuff.apple()  # get apple from module
mystuff.tangerine  # same thing, it's just a variable

# dict style
mystuff['apples']

# module style
mystuff.apples()


#  classes are like modules
class MyStuff(object):
    def __init__(self):
        self.tangerine = "And now a thousand years between"

    def apple(self):
        print("I AM CLASSY APPLES!")


# class style
thing = MyStuff()
thing.apples()
print(thing.tangerine)
Ejemplo n.º 3
0
'''

# next we can create a class just like the mystuff module
class MyStuff(object):

	def __init__(self):
		self.tangerine = "And now a thousand years between"

	def apple(self):
		print "I AM CLASSY APPLES!"

# now we instantiate (create) a class by calling the class like it's a function
thing = MyStuff()
thing.apple()
print thing.tangerine

'''
# we now have three ways to get things from things
# dictionary style
mystuff['apple']

# module style
mystuff.apples()
print mystuff.tangerine

# class styles
thing = MyStuff()
thing.apples()
print thing.tangerine
'''