Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Define and modify strings principle in Python     - Use web2py + uWSGI + Nginx Web server built on Linux (Server)

- Oracle Data File Management (Database)

- Linux System Getting Started Tutorial: How do you know Shell which is currently being used (Linux)

- Embedded Linux to solve the problem in the time zone (Linux)

- Defensive programming in PHP (Programming)

- Python object-oriented programming (Programming)

- fcntl file locking function add (Programming)

- Amazon EC2 server using Rsync + Inotify real-time synchronization (Server)

- SQL MySQL query table duplicate data (Database)

- 20+ Best Practices article MySQL Performance Optimization (Database)

- Linux system - The understanding cpu load (Linux)

- U disk to install Windows and Ubuntu 15.04 dual system (Programming)

- Depth Java Singleton (Programming)

- Oracle partition table data migration, process management automation (Database)

- To install Redis under Linux (Database)

- HTML5 Fundamentals study notes (Programming)

- Python several standard types of built-in functions (Programming)

- How to create a binary distribution with Bash (Linux)

- Linux system versions organize local root password cracking method (Linux)

- Snort build a secure Linux server (Linux)

  Define and modify strings principle in Python
  Add Date : 2016-08-02      
  Python is written in C language developed in the C language is no concept of a string, only the characters and an array of characters, usually represented by an array of characters strings, so the definition of a string in Python when, in fact, opened an in-memory space,


Define a string string1 = hello ---------> 5 characters

An array of characters [ 'h', 'e', ​​'l', 'l', 'o'], which is stored in memory location: [ 'h', 'e', ​​'l', 'l', 'o']

And if you want to modify the string is hellosb, the need to re-open a block of data in memory space: [ 'h', 'e', ​​'l', 'l', 'o', 's',' b ']

Also: If you want to modify the hello string to hello0, then open up in memory space [ 'h', 'e', ​​'l', 'l', 'o', '0']

Also, if the string concatenation:

"Hello" + 'sb' + "alex"

Principle in memory can be understood as:

First, open up an address space to store 000001: "hello"

Because "hello" + 'sb', so to open up again in the next piece of memory storage space 000002 "hello" + 'sb'

Because "hello" + 'sb' plus another string "alex" behind

It also opened a store address space 000003 "hello" + 'sb' + "alex"

In summary:

If you want to achieve three strings "hello" + 'sb' + "alex" added the need to open up three address spaces

000001 --------> "hello"

000002 ---------> "hello" + 'sb'

000003 ---------> "hello" + 'sb' + "alex"

Note: The above principle also applies to C # and JAVA

Or more extra space in front of the C language can be automatically released, C # and JAVA is a high-level language, they are assigned to free up additional space in front of the garbage collection mechanism through the virtual machine (for example: 000001,000002)


Python interpreter executes the file through stages:

1, the memory load ---> lexical analysis ---> syntax analysis ---> Production compiled into byte code ---> virtual machine interpreter into machine code and then run to the CPU

2, three coding:

ascii: only represent 256 characters, because it is represented by 8 bits, or 8 2 ^ 256 possible

Unicode: a minimum of 16 bits to represent a character, that is a minimum of two bytes to represent characters

utf8: use utf8 reason is because some of the characters in the Unicode representation with eight since you can, and use 16 to represent it appears that waste, so use utf8, it can be said utf8 is an improved version of the Unicode

3, the script parameter [Get parameters sys module's argv function]

4, byte code: the suffix .pyc files, if you import a file, and execute it, then the file is imported automatically generate .pyc file; if the file is imported in addition to its .pyc generated content is the same, during the execution of a higher priority than .pyc file is imported (.py), if the file is imported to make changes, you need to recompile and then generate .pyc files.

5. Affirms variables Note:

1)Python variables can only be numbers, letters, and underscores

2)Beginning in Python variable can not be a number

3)Python variable name can not be specified in a keyword system

6, variable assignment

If after variable assignment and then assign variables to be, you need to re-open in memory address space segment, the C language is concerned there is no string, C language string representing the array of characters; why not let the string dynamic changes, and every time you want to assign? Python array represents an array of characters in memory address when it is continuous, if not continuous, then the latter address will empty out, that for a variable length of the unknown, the address to be vacated later if we do not know , and it is unpredictable, so Python variable addresses are continuous. In solving this problem, there are internal Python buffer pool or pond or called digital string pool concept, it has a Python space it will go through its own calculations, the numbers that you use frequently put it inside the region, when we use this frequently used strings to be avoided at a time to open up space in memory.

For the small number of buffer space: -5 to 257

For large numbers of buffer space 8 to 1000
- Math objects easily overlooked but very convenient method --JavaScript (Programming)
- FreeRadius installation process record (Linux)
- Chrome plug-in management, online-offline installation, part of the plug presentations (Linux)
- C # C ++ Java interface type conversion (Programming)
- Linux module mechanism of (Programming)
- HTTP and HTTPS request response process difference (Linux)
- How MySQL tracking sql statement (Database)
- Oracle LONG RAW BLOB CLOB type of presentation (Database)
- First start with Kali Linux 2.0 (Linux)
- Object Oriented Programming Java reflection (Programming)
- Keepalived achieve high availability Nginx Reverse Proxy (Server)
- To delete the directory and all specified files under the Mac (Linux)
- GitLab Guide installation under Ubuntu 14.04 (Server)
- CentOS 6.3 compile and install LNMP environment (Server)
- MySQL group_con cat_max_Len (Database)
- Lenovo Ultrabooks Ubuntu system can not open the wireless hardware switch solutions (Linux)
- Redis-2.8.17 installation and configuration process some errors (Linux)
- Practical top command (Linux)
- How to create a bootable USB disk to use MultiSystem on Ubuntu (Linux)
- Linux garbled file delete method (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.