qiuyouzhi 发表于 2020-3-21 15:51:09

Python sys.intern()

本帖最后由 一个账号 于 2020-3-21 15:52 编辑

Python sys.intern()

>>> import sys
>>> sys.intern("qwe")
'qwe'
>>> a = sys.intern("qwe")
>>> a
'qwe'

你们觉得这个东西有什么用呢?

官方文档是这么写的:

intern(string, /)
    ``Intern'' the given string.
   
    This enters the string in the (global) table of interned strings whose
    purpose is to speed up dictionary lookups. Return the string itself or
    the previously interned string object with the same value.

qiuyouzhi 发表于 2020-3-21 16:00:15

@一个账号 @zltzlt @_2_ @wuqramy

一个账号 发表于 2020-3-21 16:00:42

qiuyouzhi 发表于 2020-3-21 16:00
@一个账号 @zltzlt @_2_ @wuqramy

https://fishc.com.cn/thread-158679-1-1.html

一个账号 发表于 2020-3-21 16:01:17

@_2_ 加个好友

qiuyouzhi 发表于 2020-3-21 16:03:55

一个账号 发表于 2020-3-21 16:00
https://fishc.com.cn/thread-158679-1-1.html

可以举个例子吗?
比如intern的实际用途?

一个账号 发表于 2020-3-21 16:10:06

qiuyouzhi 发表于 2020-3-21 16:03
可以举个例子吗?
比如intern的实际用途?

不是写了吗:为了提高字符串使用的效率和使用性能

wuqramy 发表于 2020-3-22 15:42:08

呵呵 我也不了解
页: [1]
查看完整版本: Python sys.intern()