28th Jun 2023, 3:50 PM
Podle Playz
Podle Playz - avatar
19 Respuestas
28th Jun 2023, 4:06 PM
Lisa
Lisa - avatar
+ 8
Take a break, watch the second half of the tutorial, then clarify what you want to do.
28th Jun 2023, 4:03 PM
Lisa
Lisa - avatar
+ 3
What is it supposed to do? You define a class but never create an object. Which output do you expect?
28th Jun 2023, 4:01 PM
Lisa
Lisa - avatar
+ 2
In python Classes, the __init__() method initialize any member inside it. Its first argument must be self, and you need to name the member in its paramtheses. class test: def __init__(self,name,age): self.name = name self.age = age With __init__(), when you instantiate an object(of the class) outside the class, you can pass the "parameter" to the object. Also, when calling member that has been initialized in the __init__() method(with self), you have to put "self.", With the member name. class Car: def __init__(self,name,age): self.name = name self.age = age def showInfo(self): print("Name: ",self.name,""\nAge:",self.age) car1 = Car("Mercedes car", 2000) car1.showinfo()
28th Jun 2023, 4:31 PM
Dragon RB
Dragon RB - avatar
+ 2
# with __init__ method can be defined a default object class car: def __init__(self, brand): self.brand=brand def about_car(self): print(self.brand) car_1 = car('Ferrari') mercedes = car('Mercedes') car_1.about_car()
28th Jun 2023, 4:36 PM
JaScript
JaScript - avatar
+ 1
It's on pc.
28th Jun 2023, 4:04 PM
Podle Playz
Podle Playz - avatar
+ 1
Podle Playz When you'd use the __init__() method? With __init__() method, you can declare your own variable here, and it can be accessed by the method of the class! So it is always a good practice to add and put the __init__() method in the top of the class.. you can also create a variable inside it WITHOUT self(a variable that is created and can be used to serve class stuff),but DON'T pass it to the parantheses of the __init__() method as parameter In my opinion, "self' refers to the "parameter" passed to the class.. I don't know if it's correct, since I'm not familar with Python classes..
28th Jun 2023, 4:40 PM
Dragon RB
Dragon RB - avatar
+ 1
Ok thx
28th Jun 2023, 4:43 PM
Podle Playz
Podle Playz - avatar
+ 1
U need help or u have solved it?
30th Jun 2023, 4:45 AM
S2XPHOENIX🇮🇳
S2XPHOENIX🇮🇳 - avatar
+ 1
The provided code defines a class named car with a constructor (__init__ method) that takes a parameter called make. The constructor initializes an instance variable make with the value passed to it. To create an object of the car class and assign it to the variable x with the make "Honda," you can use the following code: python Copy code class car: def __init__(self, make): self.make = make x = car("Honda") To access the make attribute of the x object, you can use the dot notation (x.make) and print it as follows: python Copy code print(x.make) When you run the complete code, it will output: Copy code Honda This means the make attribute of the x object is set to "Honda" and successfully printed using the print statement.
30th Jun 2023, 1:05 PM
Mc Rey Pangandoyon Quiao
Mc Rey Pangandoyon Quiao - avatar
+ 1
S2XPHOENIX solved
30th Jun 2023, 2:37 PM
Podle Playz
Podle Playz - avatar
+ 1
Podle Playz okie gud
30th Jun 2023, 2:56 PM
S2XPHOENIX🇮🇳
S2XPHOENIX🇮🇳 - avatar
30th Jun 2023, 2:56 PM
Podle Playz
Podle Playz - avatar
0
I don't know how to use __init__
28th Jun 2023, 3:51 PM
Podle Playz
Podle Playz - avatar
0
Please show
28th Jun 2023, 3:51 PM
Podle Playz
Podle Playz - avatar
0
I watched half a tutorial before giving up, that's why I'm here 😂
28th Jun 2023, 4:02 PM
Podle Playz
Podle Playz - avatar
0
I'm just gonna doodle around with tutorials lol
28th Jun 2023, 4:06 PM
Podle Playz
Podle Playz - avatar
0
Dragon RB thanks, I know all that I just don't understand why and when you'd use that. Still very helpful!
28th Jun 2023, 4:32 PM
Podle Playz
Podle Playz - avatar
30th Jun 2023, 3:50 PM
Podle Playz
Podle Playz - avatar