<?xml version="1.0" encoding="gbk"?>
<rss version="2.0">
  <channel>
    <title>飞克网 - python</title>
    <link>http://sou-a.com/forum.php?mod=forumdisplay&amp;fid=59</link>
    <description>Latest 20 threads of python</description>
    <copyright>Copyright(C) 飞克网</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Sun, 03 May 2026 12:04:38 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>http://sou-a.com/static/image/common/logo_88_31.gif</url>
      <title>飞克网</title>
      <link>http://sou-a.com/</link>
    </image>
    <item>
      <title>多层表达式</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=154</link>
      <description><![CDATA[for循环可以嵌套，因此，在列表生成式中，也可以用多层 for 循环来生成列表。对于字符串 \'ABC\' 和 \'123\'，可以使用两层循环，生成全排列：&gt;&gt;&gt; [m + n for m in \'ABC\' for n in \'123\'][\'A1\', \'A2\', \'A3\', \'B1\', \'B2\', \'B3\', \'C1\', \'C2\', \'C3\']翻译成循环代码就像下面这样 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sat, 15 Jul 2017 12:09:02 +0000</pubDate>
    </item>
    <item>
      <title>条件过滤</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=153</link>
      <description><![CDATA[列表生成式的 for 循环后面还可以加上 if 判断。例如：&gt;&gt;&gt; [x * x for x in range(1, 11)][1, 4, 9, 16, 25, 36, 49, 64, 81, 100]如果我们只想要偶数的平方，不改动 range()的情况下，可以加上 if 来筛选：&gt;&gt;&gt; [x * x for x in range(1, 11) if x % 2 == 0][4, 16, 36, ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sat, 15 Jul 2017 12:08:35 +0000</pubDate>
    </item>
    <item>
      <title>复杂表达式</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=152</link>
      <description><![CDATA[使用for循环的迭代不仅可以迭代普通的list，还可以迭代dict。假设有如下的dict：d = { \'Adam\': 95, \'Lisa\': 85, \'Bart\': 59 }完全可以通过一个复杂的列表生成式把它变成一个 HTML 表格：tds = [\'%s%s\' % (name, score) for name, score in d.iteritems()]print \'\'print  ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sat, 15 Jul 2017 12:07:39 +0000</pubDate>
    </item>
    <item>
      <title>生成列表</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=151</link>
      <description><![CDATA[要生成list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]，我们可以用range(1, 11)：&gt;&gt;&gt; range(1, 11)[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]但如果要生成[1x1, 2x2, 3x3, ..., 10x10]怎么做？方法一是循环：&gt;&gt;&gt; L = []&gt;&gt;&gt; for x in range(1, 11):...    L.append(x * x)... &gt;&gt;&gt; L[1, 4,  ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sat, 15 Jul 2017 12:04:26 +0000</pubDate>
    </item>
    <item>
      <title>迭代dict的key和value</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=150</link>
      <description><![CDATA[我们了解了如何迭代 dict 的key和value，那么，在一个 for 循环中，能否同时迭代 key和value？答案是肯定的。首先，我们看看 dict 对象的 items() 方法返回的值：&gt;&gt;&gt; d = { \'Adam\': 95, \'Lisa\': 85, \'Bart\': 59 }&gt;&gt;&gt; print d.items()[(\'Lisa\', 85), (\'Adam\', 95), (\'Bar ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Mon, 10 Jul 2017 14:47:07 +0000</pubDate>
    </item>
    <item>
      <title>迭代dict的value</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=149</link>
      <description><![CDATA[我们已经了解了dict对象本身就是可迭代对象，用 for 循环直接迭代 dict，可以每次拿到dict的一个key。如果我们希望迭代 dict 对象的value，应该怎么做？dict 对象有一个 values() 方法，这个方法把dict转换成一个包含所有value的list，这样，我们迭代的就是 dict的每一 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Mon, 10 Jul 2017 14:43:23 +0000</pubDate>
    </item>
    <item>
      <title>索引迭代</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=148</link>
      <description><![CDATA[Python中，迭代永远是取出元素本身，而非元素的索引。对于有序集合，元素确实是有索引的。有的时候，我们确实想在 for 循环中拿到索引，怎么办？方法是使用 enumerate() 函数：&gt;&gt;&gt; L = [\'Adam\', \'Lisa\', \'Bart\', \'Paul\']&gt;&gt;&gt; for index, name in enumerate(L):...     pr ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Mon, 10 Jul 2017 14:40:53 +0000</pubDate>
    </item>
    <item>
      <title>什么是迭代</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=147</link>
      <description><![CDATA[在Python中，如果给定一个list或tuple，我们可以通过for循环来遍历这个list或tuple，这种遍历我们成为迭代（Iteration）。在Python中，迭代是通过 for ... in 来完成的，而很多语言比如C或者Java，迭代list是通过下标完成的，比如Java代码：for (i=0; i]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Mon, 10 Jul 2017 14:38:16 +0000</pubDate>
    </item>
    <item>
      <title>对字符串切片</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=146</link>
      <description><![CDATA[字符串 \'xxx\'和 Unicode字符串 u\'xxx\'也可以看成是一种list，每个元素就是一个字符。因此，字符串也可以用切片操作，只是操作结果仍是字符串：&gt;&gt;&gt; \'ABCDEFG\'[:3]\'ABC\'&gt;&gt;&gt; \'ABCDEFG\'[-3:]\'EFG\'&gt;&gt;&gt; \'ABCDEFG\'[::2]\'ACEG\'在很多编程语言中，针对字符串提供了很多各种截取函 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 14:09:38 +0000</pubDate>
    </item>
    <item>
      <title>倒序切片</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=145</link>
      <description><![CDATA[对于list，既然Python支持L[-1]取倒数第一个元素，那么它同样支持倒数切片，试试：&gt;&gt;&gt; L = [\'Adam\', \'Lisa\', \'Bart\', \'Paul\']&gt;&gt;&gt; L[-2:][\'Bart\', \'Paul\']&gt;&gt;&gt; L[:-2][\'Adam\', \'Lisa\']&gt;&gt;&gt; L[-3:-1][\'Lisa\', \'Bart\']&gt;&gt;&gt; L[-4:-1:2][\'Adam\', \'Bart\']记住倒数第一个元素的索 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 14:07:51 +0000</pubDate>
    </item>
    <item>
      <title>对list进行切片</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=144</link>
      <description><![CDATA[取一个list的部分元素是非常常见的操作。比如，一个list如下：&gt;&gt;&gt; L = [\'Adam\', \'Lisa\', \'Bart\', \'Paul\']取前3个元素，应该怎么做？笨办法：&gt;&gt;&gt; [L[0], L[1], L[2]][\'Adam\', \'Lisa\', \'Bart\']之所以是笨办法是因为扩展一下，取前N个元素就没辙了。取前N个元素，也就是索 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 14:04:18 +0000</pubDate>
    </item>
    <item>
      <title>Python之定义可变参数</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=143</link>
      <description><![CDATA[如果想让一个函数能接受任意个参数，我们就可以定义一个可变参数：def fn(*args):    print args可变参数的名字前面有个 * 号，我们可以传入0个、1个或多个参数给可变参数：&gt;&gt;&gt; fn()()&gt;&gt;&gt; fn(\'a\')(\'a\',)&gt;&gt;&gt; fn(\'a\', \'b\')(\'a\', \'b\')&gt;&gt;&gt; fn(\'a\', \'b\', \'c\')(\'a\', \'b\', \'c\') ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 13:59:19 +0000</pubDate>
    </item>
    <item>
      <title>Python之定义默认参数</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=142</link>
      <description><![CDATA[定义函数的时候，还可以有默认参数。例如Python自带的 int() 函数，其实就有两个参数，我们既可以传一个参数，又可以传两个参数：&gt;&gt;&gt; int(\'123\')123&gt;&gt;&gt; int(\'123\', 8)83int()函数的第二个参数是转换进制，如果不传，默认是十进制 (base=10)，如果传了，就用传入的参数。 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 13:56:05 +0000</pubDate>
    </item>
    <item>
      <title>Python之递归函数</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=141</link>
      <description><![CDATA[在函数内部，可以调用其他函数。如果一个函数在内部调用自身本身，这个函数就是递归函数。举个例子，我们来计算阶乘 n! = 1 * 2 * 3 * ... * n，用函数 fact(n)表示，可以看出：fact(n) = n! = 1 * 2 * 3 * ... * (n-1) * n = (n-1)! * n = fact(n-1) * n所以，fact(n) ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 13:50:20 +0000</pubDate>
    </item>
    <item>
      <title>Python函数之返回多值</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=140</link>
      <description><![CDATA[函数可以返回多个值吗？答案是肯定的。比如在游戏中经常需要从一个点移动到另一个点，给出坐标、位移和角度，就可以计算出新的坐标：# math包提供了sin()和 cos()函数，我们先用import引用它：import mathdef move(x, y, step, angle):    nx = x + step * math.cos(ang ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 13:47:00 +0000</pubDate>
    </item>
    <item>
      <title>Python之编写函数</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=139</link>
      <description><![CDATA[在Python中，定义一个函数要使用 def 语句，依次写出函数名、括号、括号中的参数和冒号:，然后，在缩进块中编写函数体，函数的返回值用 return语句返回。我们以自定义一个求绝对值的 my_abs 函数为例：def my_abs(x):    if x &gt;= 0:        return x    else:        re ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 13:44:28 +0000</pubDate>
    </item>
    <item>
      <title>Python之调用函数</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=138</link>
      <description><![CDATA[Python内置了很多有用的函数，我们可以直接调用。要调用一个函数，需要知道函数的名称和参数，比如求绝对值的函数 abs，它接收一个参数。可以直接从Python的官方网站查看文档：http://docs.python.org/2/library/functions.html#abs也可以在交互式命令行通过 help(abs)  ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 13:40:19 +0000</pubDate>
    </item>
    <item>
      <title>Python之什么是函数</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=137</link>
      <description><![CDATA[我们知道圆的面积计算公式为：S = πr&amp;sup2;当我们知道半径r的值时，就可以根据公式计算出面积。假设我们需要计算3个不同大小的圆的面积：r1 = 12.34r2 = 9.08r3 = 73.1s1 = 3.14 * r1 * r1s2 = 3.14 * r2 * r2s3 = 3.14 * r3 * r3当代码出现有规律的重复的时候，你就需 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Sun, 09 Jul 2017 13:16:22 +0000</pubDate>
    </item>
    <item>
      <title>Python之 更新set</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=136</link>
      <description><![CDATA[由于set存储的是一组不重复的无序元素，因此，更新set主要做两件事：一是把新的元素添加到set中，二是把已有元素从set中删除。添加元素时，用set的add()方法：&gt;&gt;&gt; s = set([1, 2, 3])&gt;&gt;&gt; s.add(4)&gt;&gt;&gt; print sset([1, 2, 3, 4])如果添加的元素已经存在于set中，add()不会 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Wed, 28 Jun 2017 14:44:55 +0000</pubDate>
    </item>
    <item>
      <title>Python之 遍历set</title>
      <link>http://sou-a.com/forum.php?mod=viewthread&amp;tid=135</link>
      <description><![CDATA[由于 set 也是一个集合，所以，遍历 set 和遍历 list 类似，都可以通过 for 循环实现。直接使用 for 循环可以遍历 set 的元素：&gt;&gt;&gt; s = set([\'Adam\', \'Lisa\', \'Bart\'])&gt;&gt;&gt; for name in s:...     print name... LisaAdamBart注意: 观察 for 循环在遍历set时，元素的顺序 ...]]></description>
      <category>python</category>
      <author>admin</author>
      <pubDate>Wed, 28 Jun 2017 14:42:33 +0000</pubDate>
    </item>
  </channel>
</rss>