Storing variables / Classes / property groups in objects / scene / collection

I am a bit lost in understanging how store classes and / or property groups ,
I have followed 2 tutorials that add property groups in the Scene
(and i can see them from the panel property - custom property)
And another one have placed the properties in a scene collection
(But i dont understand if there is a panel to see these properties)
so i was wondering if i can store more complex structure of variables inside objects.
and how to do it.

PS: can you explain me the difference between the concept and usage of propertygroup and class?

add a single property to an objects in the scene :
bpy.data.objects["Cube"][" Password "]=51
Add single property to master scene collection :
bpy.context.scene.collection[" Password "] =51
Add single property to a specific collection :
bpy.data.collections["MYCOLL"]["VARIABLE"]=51

Can i store / add a class to an object ?

class BOX():
    LABEL="KITCHEN"
    N=14

Can i store / add propertygroup to an object ?

class MyPropertyGroup(bpy.types.PropertyGroup):
    custom_1: bpy.props.FloatProperty(name="My Float")
    custom_2: bpy.props.IntProperty(name="My Int")

addressing your questions in the order you asked them:

Can you explain me the difference between the concept and usage of propertygroup and class

A class is a python concept, a propertygroup is Blender specific. a class is a necessary ‘object’ concept (object as in- object oriented programming, not a “blender object”). A property group is used for storing custom properties on blender objects. They are not interchangable, and are entirely different concepts that are not compatible with each other.

Can i store / add a class to an object

No. A property group is the only “api” way to store custom structured data on a blender object. you cannot assign a class object to a custom property. If you try, python will throw an exception that explains why.

Can i store / add propertygroup to an object ?

Yes. after your propertygroup is registered, you can assign it like any other custom property.

def register():
    bpy.utils.register_class(MyPropertyGroup)
    bpy.types.Object.test_prop= MyPropertyGroup

# and then later, elsewhere in code
context.active_object.test_prop.custom_1 = 51.0
context.active_object.test_prop.custom_2 = 14

Side note: use the code tags when posting code, makes reading your post a lot easier if you do.

Aaaaaaaa thank you very much man !
i understand the mess i made now ,

I have made this test here,
and it successfully add the propertygroup to the object ,
but its like all the object share the same?
if i set the variable inside the cube01 and cube02 , when printed they are the same, the last i setted.
?

import bpy

class MyPropertyGroup(bpy.types.PropertyGroup):
    custom_1: bpy.props.FloatProperty(name="My Float")
    custom_2: bpy.props.IntProperty(name="My Int")
    
bpy.utils.register_class(MyPropertyGroup)
bpy.types.Object.test_prop= MyPropertyGroup 
 
C1=bpy.data.objects["Cube01"]
C2=bpy.data.objects["Cube02"] 
C1.test_prop.custom_1=111
C2.test_prop.custom_1=222

print ( C1.test_prop.custom_1 )
print ( C2.test_prop.custom_1 )

And the property dont appear in the panel like when im using the codes:

bpy.data.objects["Cube03"][" Password "]=51
bpy.data.objects["Cube04"][" Money "]=200

Every object get his own variable and I can check in the property panel .
Why the property group dont appear in the panel?
Props

that I don’t know, some special behavior a PropertyGroup has I would guess.

Taking a look at the code for the MeasureIt add-on might be helpful here. MeasureIt is included with recent versions of Blender. It can assign custom data to objects and display that data in a panel.

thank for reply man!
First time i read about this addon !
i will take a look but i am not sure if have some code about this.

i was just trying to put some data in a cube XD
who could have foreseen the disaster! XD