Dynamic Data Type and static data type, Dynamic Data Type Static

Source: Internet
Author: User

Dynamic Data Type and static data type, Dynamic Data Type Static
Dynamic Data TypePython is a dynamic data type. You do not need to specify a type for a variable. A variable in Python is a variable that points to a data unit. You cannot modify the content that points to a data unit by using the variable name.

// The function id () is used to view the memory address pointed to by the variable. See help (id) // two units are allocated in the memory to store numbers 12 and 13. // X and y point to the memory address respectively, similar to the C language pointer x = 12y = 13 print 'X = ', x, id (x) print 'y =', y, id (y) // Let x point to the address of y x = yprint 'X = ', x, id (x) print 'y =', y, id (y) // two units are allocated in the memory to store numbers 15 and 16. X = 15y = 16 print 'X = ', x, id (x) print 'y =', y, id (y)
Running result:
x= 12166579468y= 13 166579456x= 13 166579456y= 13 166579456x= 15 166579432y= 16 166579420
We can see that the memory units pointed to by the variables x and y are constantly changing. The data content in a memory unit remains unchanged. For example, the memory unit 166579468 always saves data 12 until the program ends and the space is released. The type of a Python variable is determined by the Data Type in the memory unit to which it points. Therefore, you do not need to declare the type to which it points, that is, the type. Static Data Type in C Language
# Include <stdio. h> int main (int argc, char * argv []) {int x = 12, y = 13; // % d output integer, % p output pointer printf ("x = % d, x_addr = % p \ n", x, & x); printf ("y = % d, y_addr = % p \ n ", y, & y); x = y; printf (" x = % d, x_addr = % p \ n ", x, & x ); printf ("y = % d, y_addr = % p \ n", y, & y); // cache the data in the memory unit pointed to by variable x 15x = 15; y = 16; printf ("x = % d, x_addr = % p \ n", x, & x); printf ("y = % d, y_addr = % p \ n ", y, & y); return 0 ;}

  

Run the program:
// CentOS install gcc $ sudo yum install gcc // compile the. c file and generate the myapp File $ gcc-o myapp dataType. c // run myapp $./myapp

Running result:

x=12,x_addr = 0xbfd9014cy=13,y_addr = 0xbfd90148x=13,x_addr = 0xbfd9014cy=13,y_addr = 0xbfd90148x=15,x_addr = 0xbfd9014cy=16,y_addr = 0xbfd90148

  

In contrast to Python, the points of the variables x and y remain unchanged. For example, variable x always points to the memory unit 0xbfd9014c. The change is always the data content in the memory that the variable points. C language declares an int type variable, that is, allocating a piece of memory space to this variable. This memory unit always belongs to this variable and can only store int type data until memory is released. When declaring a variable in a static language, you must specify the data type, because you need to allocate a fixed size of memory space for each variable in advance.

Summary:

Dynamic Language (also known as weak type language), variables do not need to declare the type. The specific type is determined by the Data Type in the memory unit to which it points. Dynamic type, pointing to variable, the data in the memory unit is not variable. Static language (also known as strong-type language), variables need to declare the type, and the memory units pointed to by the variable can store a fixed data type. Static type, variable content, and variable orientation.

Related Article

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.