• Cours
  • Compilateur de code
  • Discuter
  • Tarification
  • Équipes
Menu
+ 1

How this code is not giving any error?

class Myclass: pass obj=Myclass() obj.n=1000 print (obj.n) As there is no attribute n how can this work

pythonclassesattributespython3oop
5th Feb 2020, 4:45 AM
Pranshu Nema
Pranshu Nema - avatar
1 Réponse
+ 2
You can do similar thing in JS. It's called monkey patching https://stackoverflow.com/questions/5626193/what-is-monkey-patching.
5th Feb 2020, 6:09 AM
Stephan
Stephan - avatar

Vous avez souvent des questions comme celle-ci ?

Apprenez de maniĂšre plus efficace, gratuitement :

  • Introduction Ă  Python

    7.1M apprenants

  • Introduction Ă  Java

    4.7M apprenants

  • Introduction Ă  C

    1.5M apprenants

  • Introduction Ă  HTML

    7.5M apprenants

Voir tous les cours
Aujourd'hui en vedette
Functions in python
2 Votes
How to make a playground
1 Votes
How can you find whether a number is odd or even in a different way(other than (x%2==0))?
1 Votes
I need advice
1 Votes
Html 5 document question
1 Votes
this query always result to be incorrect from Sorting Data lesson
1 Votes
Python
0 Votes
đ™”đ™žđ™œđ™ł đšƒđ™·đ™Ž đ™žđ™œđ™żđš„đšƒ đ™Ÿđ™” đšƒđ™·đ™Ž đ™żđšđ™Ÿđ™¶đšđ™°đ™Œ
1 Votes
Can someone explain inline and block elements please
0 Votes
Can you tell what is wrong with the code
0 Votes