str在python中用法_str如何在python中实现?

如果python字符串在weblog article by Laurent Luce中,则可以找到有关实现的一些信息。另外,您可以浏览source。在

字符串对象的大小取决于操作系统、机器类型和某些选择。在64位FreeBSD上,将unicode用于字符串文字(from __future__ import unicode_literals):In [1]: dir(str)

Out[1]: ['__add__', '__class__', '__contains__', '__delattr__', '__doc__',

'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',

'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__',

'__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__',

'__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__',

'__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split',

'_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode',

'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha',

'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust',

'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust',

'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip',

'swapcase', 'title', 'translate', 'upper', 'zfill']

In [2]: import sys

In [3]: sys.getsizeof("")

Out[3]: 52

In [4]: sys.getsizeof("test")

Out[4]: 68

In [7]: sys.getsizeof("t")

Out[7]: 56

In [8]: sys.getsizeof("te")

Out[8]: 60

In [9]: sys.getsizeof("tes")

Out[9]: 64

在这种情况下,每个字符都额外使用4个字节。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值