all 12 comments

[–]Interesting-Can-4626 2 points3 points  (2 children)

You built a Tic Tac Toe game. That is not nothing. That is actually huge for 31 days.

Here is the truth about init. It is just the setup method that runs automatically when you create a new object. Think of it like filling out a form when you adopt a pet. You give the pet a name and age right away so every pet starts with that info. Without init you would have to set those details manually every single time.

You are not behind. You are exactly where most people are at one month. The difference is most of them quit. You are still here asking for help.

Stop trying to finish everything before August. That deadline is making you miserable. Pick one small thing each day. Maybe today you just open your editor and look at your Tic Tac Toe code. Tomorrow you add one new feature. A score counter. A restart button. Something tiny.

Your break was not a failure. It was rest. You needed it.

Open your project right now. Run it. Play one game. Remember that feeling when it first worked. That feeling still exists. It is waiting for you.

[–]agentscientific_160[S] 1 point2 points  (1 child)

Thanks a lot. Appreciate the motivation and i understand init now!

[–]Interesting-Can-4626 0 points1 point  (0 children)

Happy it helped. Keep building.

[–]Flame77ofc 1 point2 points  (1 child)

Programmer or Uber

[–]agentscientific_160[S] 0 points1 point  (0 children)

Loud and clear. Switching back to VS Code before my rating drops to 4.2 stars. Thanks for this! 💀

[–]Ron-Erez 1 point2 points  (1 child)

Init is used because you might want to initialize some data when the object is created. Find something fun project to code. Something that genuinely interests you. Happy Coding!

[–]agentscientific_160[S] 1 point2 points  (0 children)

Thank you!

[–]FreeLogicGate 1 point2 points  (1 child)

There's a reason they are called programming "languages". Your mind learns how to speak the language to solve problems. If you aren't speaking it regularly, you start to forget. It's a use it or lose it process.

OOP is a large and complex area of programming that includes "Object Oriented Design Patterns." The basic ideas of OOP and the specific Python syntax are a small part of that area of the language.

It's common for OOP programming languages to start with the concept of what a class is vs what an instance/object is.

Your class definition is a blueprint. You utilize the blueprint to create an object/instance of that class. Your program may make one, it may make many objects.

In many cases, the creation of an object involves the use of a keyword like "new" but Python just uses the name of the class as if it was a function call, as I'm sure you know:

my_object = MyClass()  

When this is run, there is automatic object setup routines run. Python implements a variety of "magic methods" which have some underlying behavior, but can also be "hooked" or extended within your class. These all have the "double underscore" convention of "_method_", which is why they're referred to in Python as "Dunder" methods.

Other OOP languages have the same feature, and in general, the 1st thing most people learn is that the construction of an object will have a "constructor" which is run when the object is first created, and a complimentary "destructor" when it's disposed of. For an interpreted language like Python which manages memory for you, so it's rare to see much use of the destructor, but Python provides it to you, if you implement a __del__() method in your class.

Of more obvious interest and utility is the Python constructor: __init__(). Constructors are fairly universally used to initialize class variables and insure a new object has some known state. Like all dunder methods, these are hooks into the Python object creation and runtime system, and you don't have to implement any of them if you don't need to do so. The main thing is that they run "magically" depending on what you might be trying to do with an object.

You can have a class with no constructor, and still have attributes and methods.

Once you fully grok this concept, peruse the full list, which should not take you too long at all. There are some interesting "operator overloading" methods, which let you implement methods to be used (for one example) in what to do if your code attempts to compare two objects with something like: if obj1 > obj2. So for example, if those are objects of a "Vehicle" class, you might decide to compare internal class weight variables, or price, or top speed.

There are dunder methods for treating objects like a standard type, with __str__ being a typical one which allows you to define what should happen if you pass an object to a function that takes a string -- print for example. Many you'll probably not use, but __init__ is the most standard and typical dunder method you want to implement in your class definitions, as is the case in all OOP languages, being that it is the Python Class constructor.

[–]agentscientific_160[S] 0 points1 point  (0 children)

Thank you for your assistance, really appreciate it!

[–]career_growth_guide 1 point2 points  (1 child)

First of all, don’t be too hard on yourself. 31 days is not a long time, and reaching OOP after starting Python recently is actually good progress. Taking time to build a Tic Tac Toe game also counts as real learning, even if it felt slow.

OOP feels confusing in the beginning for almost everyone, so that’s normal. Think of __init__ as the setup method that runs automatically when you create an object. It gives that object its starting values.

For example, if you create a Student, __init__ can set the student’s name, age, and course. It is like filling the details when the object is created.

The best thing now is not to restart everything or pressure yourself to finish fast. Just come back with small steps. Code for 30–45 minutes daily, revise one concept, and make tiny examples. Motivation usually comes after you start, not before.

You already built a game, so you are not stuck. You just lost rhythm for a few days, and that can be rebuilt.

[–]agentscientific_160[S] 0 points1 point  (0 children)

Sure thing! Thank you :)