Analysis of Python Dynamic Language

Source: Internet
Author: User

In fact, Python Dynamic Language and C ++ are very similar in nature, and some changes cause serious errors, this article provides a detailed analysis and introduction of the Python dynamic language, which is a headache for most users.

The founder of Python is Guido van rosum. Prior to the invention of the Python language, Guido participated in the design of a language called ABC, which was specially designed for non-professional programmers; guido incorporates many advantages of ABC in the design of Python.

Such as ABC data type list, tuples, text, etc.), variables do not need to be declared, built-in function powerful string processing and simple control structure and other features; at the same time, some defects of the ABC language are abandoned. The most important one is to make Python easier to expand.

This is also one of the reasons why the Python language is so popular now, the first implementation of Python is on the mac machine, the design of the Python language is also affected by the Modula-3 of another beautiful and powerful language, combined with the Unix Shell and C habits.

  • How to properly program Python
  • Python examples
  • Introduction to two Python thread programming methods
  • Introduction to Python thread entity
  • Introduction to Python syntax

Currently, Python is an OpenSource project, and the Python community is very active, which greatly promotes the development of Python Dynamic Language. The latest version of Python is 2.4.2. Python is an object-oriented, cross-platform, and extensible interpreted universal programming language. It supports modules and packages. There are three types of Python code :. py. pyc. pyo is the byte code.

Binary Code and optimization code can be directly run without any compilation or link steps, and Python also provides an interactive execution environment. Python dynamic type language does not require type declaration; provides automatic memory management, built-in support for advanced data types and operations, Python scalability and embedding, simple syntax and clear code readability, dynamic loading of C modules, and dynamic loading of Python modules;

Python is a dynamic language that allows you to dynamically add and delete functions while the program is running. You can dynamically add and modify classes and instances at runtime. Python is an internal language; provides standard GUI framework to develop graphical interfaces; supports standard Internet protocols; supports built-in and third-party libraries and rich library support; free use and full open source code.

 
 
  1. >>>Type ([])
  2.  
  3. <Type'LIST'>
  4.  
  5. >>>Import sys
  6.  
  7. >>>Type (sys)
  8.  
  9. <Type'Module'>
  10.  
  11. >>>Type (dir)
  12.  
  13. <Type'Builtin _ function_or_method'>
  14.  
  15. The hasattr () and getattr () functions retrieve attributes of an object.
  16.  
  17. >>>Import OS
  18.  
  19. >>>Hasattr (OS. dup, '_ doc __')
  20.  
  21. True
  22.  
  23. >>>Print getattr (OS. dup, '_ doc __')
  24.  
  25. Dup (fd )->Fd2
  26.  
  27. Return a duplicate of a file descriptor.
  28.  
  29. Callable () function test object callability:
  30.  
  31. >>>Callable ('string ')
  32.  
  33. False
  34.  
  35. >>>Callable (callable)
  36.  
  37. True

The Python dynamic language does not provide explicit memory allocation and recovery APIs, allowing for completely automatic memory management. Python memory manager manages the heap when the program is running, including memory allocation, garbage collection mechanism; garbage collection, hereinafter referred to as GC) in the current version, the reference garbage collection and optional cyclic structure garbage space scanning technology are used.

Once the object becomes inaccessible, it will be recycled, but it cannot be guaranteed to recycle the memory garbage that contains the cyclic reference count. The reference counting algorithm is more intuitive: records the number of pointers to each bucket, and updates the reference counting when performing some operations on the bucket.

When a bucket is allocated, the reference count is initialized to 1. As long as the bucket reference is copied, the reference count is incremented by 1. When the bucket reference is deleted, the reference count is reduced by 1, if the reference count is reduced to 0, the storage slice will be recycled due to inaccessibility. Obviously, the counting algorithm cannot recycle the circular data structure. Imagine a simple scenario: a member of object a points to object B, and B also points to, in addition, the Code only references part.

Object B is generated only by the aid of object a. If object a is deleted later, both object a and object B become memory garbage as a whole. In theory, object B should be deleted by the Memory Manager, however, since the reference counting algorithm only examines one node at a time, the cyclic data structure cannot be recycled. Therefore, we should try to avoid loop references during programming.

  1. How to embed Python into C ++ applications?
  2. In-depth discussion of Ruby and Python syntax comparison
  3. Introduction to Python
  4. Python Learning Experience: version, IDE selection and coding Solutions
  5. Analysis of Python GIL and thread security

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.