分类: Python/Ruby
2015-08-04 19:40:23
wq41132015-08-04 19:41:41
10.dictionary中的解析
>>> params = {\"server\":\"mpilgrim\", \"database\":\"master\", \"uid\":\"sa\", \"pwd\":\"secret\"} >>> params.keys() [\'server\', \'uid\', \'database\', \'pwd\'] >>> params.values() [\'mpilgrim\', \'sa\', \'master\', \'secret\'] >>> params.items() [(\'server\', \'mpilgrim\'), (\'uid\', \'sa\'), (\'database\', \'master\'), (
wq41132015-08-04 19:41:35
8.list 分割字符串
>>> li = [\'server=mpilgrim\', \'uid=sa\', \'database=master\', \'pwd=secret\'] >>> s = \";\".join(li) >>> s \'server=mpilgrim;uid=sa;database=master;pwd=secret\' >>> s.split(\";\") [\'server=mpilgrim\', \'uid=sa\', \'database=master\', \'pwd=secret\'] >>> s.split(\";\", 1) [\'server=mpilgrim\', \'uid=sa;database=master;pwd=secret\']
split 与 join 正好相
wq41132015-08-04 19:41:06
6.list 运算符
>>> li = [\'a\', \'b\', \'mpilgrim\'] >>> li = li + [\'example\', \'new\'] >>> li [\'a\', \'b\', \'mpilgrim\', \'example\', \'new\'] >>> li += [\'two\'] >>> li [\'a\', \'b\', \'mpilgrim\', \'example\', \'new\', \'two\'] >>> li = [1, 2] * 3 >>> li [1, 2,