List to string

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:31 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
list to string
array to string

1 PHP[ | ]

PHP
Copy
$arr = [10,"test",10.5];
$str = print_r( $arr, true );
echo gettype($str) . PHP_EOL;
print_r( $str );
# string
# Array
# (
#     [0] => 10
#     [1] => test
#     [2] => 10.5
# )
PHP
Copy
$arr = [10,"test",10.5];
$str = var_export( $arr, true );
echo gettype($str) . PHP_EOL;
print_r( $str );
# string
# array (
#   0 => 10,
#   1 => 'test',
#   2 => 10.5,
# )

2 Python[ | ]

  • Python 2
Python
Copy
mylist = [10,"test",10.5]
mystr = str(mylist)
print( type(mystr) )
print( mystr )
# <type 'str'>
# [10, 'test', 10.5]