小编dzt*_*dzt的帖子

Ruby版本的String方法

这个问题是关于格式化ruby的字符串.

在Python中,内置数据结构具有内置的字符串方法,因此当打印变量时,字符串可以方便地格式化以反映所使用的数据结构.例如:

>>>$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
$>>> a = [1,2,3,4]
$>>> str(a)
'[1, 2, 3, 4]'
$>>> print a
[1, 2, 3, 4]
$>>> d = { "a":"a", "b":"b", 1:5 }
$>>> str(d)
"{'a': 'a', 1: 5, 'b': 'b'}"
$>>> print d
{'a': 'a', 1: 5, 'b': 'b'}
$>>> x = [1, 23, 4]
$>>> print x
[1, 23, 4]
Run Code Online (Sandbox Code Playgroud)

请注意,当我打印a时,值为 [1, …

ruby python

5
推荐指数
2
解决办法
6509
查看次数

标签 统计

python ×1

ruby ×1