Amazing Dynamic Language

Source: Internet
Author: User
I have been curious about dynamic languages, but I have never officially used dynamic features of dynamic languages. The most commonly used method is to use JavaScript as an imperative language to operate HTML Dom.

Today I saw a video about ironpython. I was shocked by the powerful dynamic language features. You can add methods/attributes or replace methods to a class at runtime.

The following is a command script that can be used in the ironpython console.

>>> Def Foo (Self): "" defines a method.
... Print 1
...
>>> Class ctest: "defines a class
... Def bar (Self ):
... Print 2
...
>>> T1 = ctest () "creates an instance of a class.
>>> T1.bar ()"""
2
>>> Ctest. Foo = foo "" adds a dynamic method for the class.
>>> T1.foo ()
1
>>> Def func1 (Self ):
... Self. Bar ()
...
>>> Ctest. func1 = func1
>>> T1.func1 ()
2
>>> T1.func1 ()
2
>>> T1.a = 1 "dynamically adds an attribute to an object.
>>> Def func2 (Self ):
... Print self.
...
>>> Ctest. func2 = func2
>>> T1.func2 ()
1
>>>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.