You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
self.multiLbl("Now, we're finally going to answer that question: \"WHAT THE HECK IS A METHOD?!?!?!?!?!?!?!?!?!\" Geez. Stop commenting. ITS BAD 4 UR PUNCSHOOASHUN CUPZ LOC KEE AN SPELEENG. IT WILL TURN THE SQL DATABASE THAT I DON'T READ INTO A YOUTUBE COMMENTS! I LITTERALLY MAKE THE WORDS UR COMMENT HAS BEEN RECIEVED APPEAR EVEN IF I NEVER READ IT!!! SHOOT MY CUZ LUC KEE IZ BROCEN I M USING A MAC ALL MY TEXT IS NOW AND FOREVER CAPITALIZED :(:(:(:(:(:(:(")
137
+
self.multiLbl("Now, we're finally going to answer that question: \"WHAT THE HECK IS A METHOD?!?!?!?!?!?!?!?!?!\" Geez. Stop commenting. ITZ BAD 4 UR PUNCSHOOASHUN CUPZ LOC KEE AN SPILEENG. IT WILL TURN THE SQL DATABASE THAT I DON'T READ INTO A YOUTUBE COMMENTS! I LITTERALLY MAKE THE WORDS UR COMMENT HAS BEEN RECIEVED APPEAR EVEN IF I NEVER READ IT!!! SHOOT MY CUPZ LUC KEE IZ BROCEN I M USING A MAC ALL MY TEXT IS NOW AND FOREVER CAPITALIZED :(:(:(:(:(:(:(")
121
138
self.multiLbl("SO, ANYWAYS, A METHOD IS A FUNCTION INSIDE OF A CLASS. \"WHAT ARE FUNCTIONS AND CLASSES?\" YOU WILL FIND OUT NEXT LESSON.")
122
139
123
140
deffunctions(self):
124
141
self.new_lesson(1, 10)
125
142
self.multiLbl("A function. Use:\n def function_name(args):\n\t#insert_code_here\n to create a function and function_name(args) to call it. You can have as many args as you want and they can be whatever you want. Be warned. Functions are eeeeevvvvveeeeerrrrryyyyywwwwwhhhhheeeeerrrrreeeee. Print is a function. Input is a function. If you look at the source code, you might see functions such as eval and exec. There are many other functions just 2 name a few.")
143
+
144
+
defoop(self):
145
+
self.new_lesson(1, 11)
146
+
self.multiLbl("You thought this lesson was going to be about classes? Ha! weeeelllllll, technically object oriented programming is classes. You see, a class has the basic methods and variables. An object is one version of a class. Let me explain and show you the syntax for a class at the same time by making a student class. I'll show you how.")
147
+
code="""class Student:\t\t\t
148
+
\tdef __init__(self, name, grade, gpa):\t
149
+
\t\tself.name = name\t\t\t
150
+
\t\tself.grade = grade\t\t\t
151
+
\t\tself.gpa = gpa\t\t\t\t\t
152
+
\tdef __repr__(self):\t\t\t
153
+
\t\tprint(self.name+" has been in school for "+str(grade+1)+" years and his gpa is "+str(gpa)
154
+
155
+
billy = Student(\"Billy Bob Joe\", 5, 3.95)
156
+
print(billy)"""
157
+
self.cenBtn(code, lambda: exec(code))
158
+
self.cenLbl("Two underscores signify a special keyword, and in the case of a class, it's usually a method name. The __init__ method is run as soon as the object is initialized, and it takes in self and whatever other arguments you want it to. Self refers to the class. The __repr__ and __str__ methods are what happen when you want it to be a string, __repr__ is like the official one and __str__ is called when you use str(object_name). You also have __del__ and __call__ and many, many more. You can also create methods but the first argument is always self and to run it from another method in the class, you have to do self.method_name or you can run it like ObjectName.method_name. You can also have static methods which are called by ClassName.method_name(args) and don't have a self. To define a static method, you do @staticmethod above the line with the method.")
126
159
160
+
defloops(self):
161
+
self.new_lesson(1, 12)
162
+
self.multiLbl("I'm doing this out of order but who cares. A loop is something that repeats. There are two types of loops. A for loop and a while loop. This should show you the difference")
163
+
code="""for item in ["Hello,", "World!", "foo", "bar"]:
164
+
\tprint(item)"""
165
+
self.cenBtn(code, lambda: exec(code))
166
+
code="""i = 0
167
+
while i < 4:
168
+
\tprint(i)
169
+
i += 1"""
170
+
self.cenBtn(code, lambda: exec(code))
171
+
self.multiLbl("So as you can see, a for loop loops for every item in a list and a while loop repeats while a condition is true. For for loops, a function that is commonly used is range(n). Range makes a list of numbers between 0 (inclusive) and n (exclusive). So range(3) returns [0, 1, 2] and range(1) returns [0]. If you're using for with a dictionary, for thing in dict will make thing the key but for key, value in dict will have key as the key and value as the value. Mind blown. A while loop will run while the condition is True.")
0 commit comments