Quote (known954 @ Feb 10 2015 11:21am)
yeah, its my first programming class ever and a lot of the functions you use I am not familiar with, such as : def ; class ; self ; check
def creates a function, which can be standalone or created inside of a
class.
Code
def name():
""" This asks your name and returns a reference of your name"""
name = input("What's your name? ")
return name
Code
class Name(object):
def __init__(self, name):
self.name = name
def uppercase(self):
""" Make your name uppercase """
return self.name.upper()
def titled(self):
""" Make your name titled """
return self.name.title()
def lowercase(self):
""" Make your name lowercase """
return self.name.lower()
So creating them is half the battle, now you have to use them properly.
A function you can use a few ways, you call call it directly
name() or you can assign it to something to reference it later
my_name = name() self can be anything, you don't have to call it self but it is a Python standard to use the value self, which is passed around a class and inherited by other functions and objects within it. The advantage of using OOP is this inheritance.
So back to using this mess.
If you save those in the same file and call it like this
python3 -i scriptname.py
You are able to play around with the functions within it
Code
>>> my_name = name()
>>> change = Name(my_name)
>>> dir(change)
>>> change.uppercase
<bound method Name.uppercase of <__main__.Name object at 0x7fa0550ad898>>
>>> change.uppercase()
'RICK'
>>> change.lowercase()
'rick'
>>> change.titled()
'Rick'
>>>