Browse files

Site updated at 2013-01-29 06:01:38 UTC

  • Loading branch information...
1 parent 3082b09 commit 3e83942cea349bada408ed3b9225a293fe47c262 @mikegao committed Jan 29, 2013
View
4 about/index.html
@@ -158,6 +158,10 @@ <h1 class="entry-title"></h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/beginner-of-python/">Beginner_Of_Python</a>
+ </li>
+
+ <li class="post">
<a href="/blog/hello-world/">Hello World</a>
</li>
View
23 archives/index.html
@@ -9,8 +9,9 @@
<meta name="author" content="Mike Gao">
- <meta name="description" content=" Blog Archive 2013 Hello World
-Jan 29 2013 About Me A rubyer, Apple User Recent Posts Hello World ">
+ <meta name="description" content="Blog Archive 2013 Beginner_Of_Python
+Jan 29 2013 posted in python Hello World
+Jan 29 2013 About Me A rubyer, Apple User Recent Posts &hellip;">
<!-- http://t.co/dKP3o1e -->
@@ -78,6 +79,20 @@ <h1 class="entry-title">Blog Archive</h1>
<article>
+<h1><a href="/blog/beginner-of-python/">Beginner_Of_Python</a></h1>
+<time datetime="2013-01-29T10:42:00+08:00" pubdate><span class='month'>Jan</span> <span class='day'>29</span> <span class='year'>2013</span></time>
+
+<footer>
+ <span class="categories">posted in <a class='category' href='/blog/categories/python/'>python</a></span>
+</footer>
+
+
+</article>
+
+
+
+<article>
+
<h1><a href="/blog/hello-world/">Hello World</a></h1>
<time datetime="2013-01-29T10:23:00+08:00" pubdate><span class='month'>Jan</span> <span class='day'>29</span> <span class='year'>2013</span></time>
@@ -117,6 +132,10 @@ <h1 class="entry-title">Blog Archive</h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/beginner-of-python/">Beginner_Of_Python</a>
+ </li>
+
+ <li class="post">
<a href="/blog/hello-world/">Hello World</a>
</li>
View
202 atom.xml
@@ -4,7 +4,7 @@
<title><![CDATA[Mike Tech]]></title>
<link href="http://mikegao.github.com/atom.xml" rel="self"/>
<link href="http://mikegao.github.com/"/>
- <updated>2013-01-29T10:25:19+08:00</updated>
+ <updated>2013-01-29T14:00:47+08:00</updated>
<id>http://mikegao.github.com/</id>
<author>
<name><![CDATA[Mike Gao]]></name>
@@ -14,6 +14,206 @@
<entry>
+ <title type="html"><![CDATA[Beginner_Of_Python]]></title>
+ <link href="http://mikegao.github.com/blog/beginner-of-python/"/>
+ <updated>2013-01-29T10:42:00+08:00</updated>
+ <id>http://mikegao.github.com/blog/beginner-of-python</id>
+ <content type="html"><![CDATA[<h4>变量交换</h4>
+
+<pre><code>x = 6
+y = 5
+
+x, y = y, x
+print x
+&gt;&gt;&gt; 5
+print y
+&gt;&gt;&gt; 6
+</code></pre>
+
+<h4>if 语句再行内</h4>
+
+<pre><code>print "Hello" if True else "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+
+<h4>连接</h4>
+
+<p> 下面的最后一种方式在绑定两个不同类型的对象时显得很cool</p>
+
+<pre><code>nfc = ["Packers", "49ers"]
+afc = ["Ravens", "Patriots"]
+print nfc + afc
+&gt;&gt;&gt; ['Packers', '49ers', 'Ravens', 'Patriots']
+
+print str(1) + " world"
+&gt;&gt;&gt; 1 world
+
+pring 1, "world"
+&gt;&gt;&gt; 1 world
+
+print nfc, 1
+&gt;&gt;&gt; ['Packers', '49ers'] 1
+</code></pre>
+
+<h4>数字技巧</h4>
+
+<pre><code># 除后向下取整
+print 5.0//2
+&gt;&gt;&gt; 2
+# 2的5次方
+print 2**5
+&gt;&gt;&gt; 32
+</code></pre>
+
+<h4>注意浮点数的除法</h4>
+
+<pre><code>print .3/.1
+&gt;&gt;&gt; 2.9999999999999996
+print .3//.1
+&gt;&gt;&gt; 2.0
+</code></pre>
+
+<h4>数值比较</h4>
+
+<pre><code>x = 2
+if 3 &gt; x &gt; 1:
+ print x
+&gt;&gt;&gt; 2
+if 1 &lt; x &gt; 0:
+ print x
+&gt;&gt;&gt; 2
+</code></pre>
+
+<h4>同时迭代两个列表</h4>
+
+<pre><code>nfc = ['Packers', '49ers']
+afc = ['Ravens', 'Patriots']
+for teama, teamb in zip(nfc, afc)
+ print teama + " vs. " + teamb
+&gt;&gt;&gt; Packers vs. Ravens
+&gt;&gt;&gt; 49ers vs. Patriots
+</code></pre>
+
+<h4>带索引的列表迭代</h4>
+
+<pre><code>teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for index, team in enumerate(teams):
+ print index, team
+&gt;&gt;&gt; 0 Packers
+&gt;&gt;&gt; 1 49ers
+&gt;&gt;&gt; 2 Ravens
+&gt;&gt;&gt; 3 Patriots
+</code></pre>
+
+<h4>列表推导式</h4>
+
+<p> 已知一个列表,我们可以刷选出偶数列表方法</p>
+
+<pre><code>numbers = [1,2,3,4,5]
+even = [number for number in numbers if number%2 == 0]
+</code></pre>
+
+<h4>字典推导</h4>
+
+<p> 和列表推导类似</p>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print {key: value for value, key in enumerate(teams)}
+&gt;&gt;&gt; {'49ers': 1, 'Ravens': 2, 'Patriots': 3, 'Packers': 0}
+</code></pre>
+
+<h4>初始化列表的值</h4>
+
+<pre><code>items = [0]*3
+print items
+&gt;&gt;&gt; [0, 0, 0]
+</code></pre>
+
+<h4>列表转换为字符串</h4>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print ", ".join(teams)
+&gt;&gt;&gt; 'Packers, 49ers, Ravens, Patriots'
+</code></pre>
+
+<h4>从字典中获取元素</h4>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+try:
+ is_admin = data['admin']
+except KeyError:
+ is_admin = False
+</code></pre>
+
+<p> 替换成这样:</p>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+is_admin = data.get('admin', False)
+</code></pre>
+
+<h4>获取列表的子集</h4>
+
+<pre><code>x= [1,2,3,4,5]
+# 前3个
+print x[:3]
+&gt;&gt;&gt; [1, 2, 3]
+# 中间4个
+print x[1:5]
+&gt;&gt;&gt; [2, 3, 4, 5]
+# 最后3个
+print x[3:]
+&gt;&gt;&gt; [4, 5, 6]
+# 奇数项
+print x[::2]
+&gt;&gt; [1, 3, 5]
+# 偶数项
+print x[1::2]
+&gt;&gt; [2, 4, 6]
+</code></pre>
+
+<h4>60个字符解决FizzBuzz</h4>
+
+<p> 写一个程序,打印数字1到100,3的倍数打印“Fizz”来替换这个数,5的倍数打印“Buzz”,对于既是3的倍数又是5的倍数的数字打印“FizzBuzz”</p>
+
+<pre><code>for x in range(101):print'fizz'[x%3*4::]+'buzz'[x%5*4::]or x
+</code></pre>
+
+<h4>集合</h4>
+
+<pre><code>from collections import Counter
+print Counter("hello")
+&gt;&gt;&gt; Counter({'1': 2, 'h': 1, 'e': 1, 'o': 1})
+</code></pre>
+
+<h4>迭代工具</h4>
+
+<p> 和collections库一样,还有一个库叫itertools,对某些问题真能高效地解决。其中一个用例是查找所有组合,他能告诉你在一个组中元素的所有不能的组合方式</p>
+
+<pre><code>from itertools import combinations
+teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for game in combinations(teams, 2):
+ print game
+&gt;&gt;&gt; ('Packers', '49ers')
+&gt;&gt;&gt; ('Packers', 'Ravens')
+&gt;&gt;&gt; ('Packers', 'Patriots')
+&gt;&gt;&gt; ('49ers', 'Ravens')
+&gt;&gt;&gt; ('49ers', 'Patriots')
+&gt;&gt;&gt; ('Ravens', 'Patriots')
+</code></pre>
+
+<h4>False == True</h4>
+
+<pre><code>False = True
+if False:
+ print "Hello"
+else:
+ print "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+]]></content>
+ </entry>
+
+ <entry>
<title type="html"><![CDATA[Hello World]]></title>
<link href="http://mikegao.github.com/blog/hello-world/"/>
<updated>2013-01-29T10:23:00+08:00</updated>
View
23 blog/archives/index.html
@@ -9,8 +9,9 @@
<meta name="author" content="Mike Gao">
- <meta name="description" content=" Blog Archive 2013 Hello World
-Jan 29 2013 About Me A rubyer, Apple User Recent Posts Hello World ">
+ <meta name="description" content="Blog Archive 2013 Beginner_Of_Python
+Jan 29 2013 posted in python Hello World
+Jan 29 2013 About Me A rubyer, Apple User Recent Posts &hellip;">
<!-- http://t.co/dKP3o1e -->
@@ -78,6 +79,20 @@ <h1 class="entry-title">Blog Archive</h1>
<article>
+<h1><a href="/blog/beginner-of-python/">Beginner_Of_Python</a></h1>
+<time datetime="2013-01-29T10:42:00+08:00" pubdate><span class='month'>Jan</span> <span class='day'>29</span> <span class='year'>2013</span></time>
+
+<footer>
+ <span class="categories">posted in <a class='category' href='/blog/categories/python/'>python</a></span>
+</footer>
+
+
+</article>
+
+
+
+<article>
+
<h1><a href="/blog/hello-world/">Hello World</a></h1>
<time datetime="2013-01-29T10:23:00+08:00" pubdate><span class='month'>Jan</span> <span class='day'>29</span> <span class='year'>2013</span></time>
@@ -117,6 +132,10 @@ <h1 class="entry-title">Blog Archive</h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/beginner-of-python/">Beginner_Of_Python</a>
+ </li>
+
+ <li class="post">
<a href="/blog/hello-world/">Hello World</a>
</li>
View
413 blog/beginner-of-python/index.html
@@ -0,0 +1,413 @@
+
+<!DOCTYPE html>
+<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
+<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
+<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
+<head>
+ <meta charset="utf-8">
+ <title>Beginner_Of_Python - Mike Tech</title>
+ <meta name="author" content="Mike Gao">
+
+
+ <meta name="description" content="变量交换 x = 6
+y = 5 x, y = y, x
+print x &gt;&gt;&gt; 5
+print y
+&gt;&gt;&gt; 6 if 语句再行内 print "Hello" if True else "World"
+&gt;&gt;&gt; Hello 连接 &hellip;">
+
+
+ <!-- http://t.co/dKP3o1e -->
+ <meta name="HandheldFriendly" content="True">
+ <meta name="MobileOptimized" content="320">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+
+
+ <link rel="canonical" href="http://mikegao.github.com/blog/beginner-of-python/">
+ <link href="/favicon.png" rel="icon">
+ <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
+ <script src="/javascripts/modernizr-2.0.js"></script>
+ <script src="/javascripts/ender.js"></script>
+ <script src="/javascripts/octopress.js" type="text/javascript"></script>
+ <link href="/atom.xml" rel="alternate" title="Mike Tech" type="application/atom+xml">
+ <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
+<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+
+
+
+</head>
+
+<body >
+ <header role="banner"><hgroup>
+ <h1><a href="/">Mike Tech</a></h1>
+
+</hgroup>
+
+</header>
+ <nav role="navigation"><ul class="subscription" data-subscription="rss">
+ <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
+
+</ul>
+
+<form action="http://google.com/search" method="get">
+ <fieldset role="search">
+ <input type="hidden" name="q" value="site:mikegao.github.com" />
+ <input class="search" type="text" name="q" results="0" placeholder="Search"/>
+ </fieldset>
+</form>
+
+<ul class="main-navigation">
+ <li><a href="/">Blog</a></li>
+ <li><a href="/blog/archives">Archives</a></li>
+</ul>
+
+</nav>
+ <div id="main">
+ <div id="content">
+ <div>
+<article class="hentry" role="article">
+
+ <header>
+
+ <h1 class="entry-title">Beginner_Of_Python</h1>
+
+
+ <p class="meta">
+
+
+
+
+
+
+
+
+
+
+
+
+<time datetime="2013-01-29T10:42:00+08:00" pubdate data-updated="true">Jan 29<span>th</span>, 2013</time>
+
+ </p>
+
+ </header>
+
+
+<div class="entry-content"><h4>变量交换</h4>
+
+<pre><code>x = 6
+y = 5
+
+x, y = y, x
+print x
+&gt;&gt;&gt; 5
+print y
+&gt;&gt;&gt; 6
+</code></pre>
+
+<h4>if 语句再行内</h4>
+
+<pre><code>print "Hello" if True else "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+
+<h4>连接</h4>
+
+<p> 下面的最后一种方式在绑定两个不同类型的对象时显得很cool</p>
+
+<pre><code>nfc = ["Packers", "49ers"]
+afc = ["Ravens", "Patriots"]
+print nfc + afc
+&gt;&gt;&gt; ['Packers', '49ers', 'Ravens', 'Patriots']
+
+print str(1) + " world"
+&gt;&gt;&gt; 1 world
+
+pring 1, "world"
+&gt;&gt;&gt; 1 world
+
+print nfc, 1
+&gt;&gt;&gt; ['Packers', '49ers'] 1
+</code></pre>
+
+<h4>数字技巧</h4>
+
+<pre><code># 除后向下取整
+print 5.0//2
+&gt;&gt;&gt; 2
+# 2的5次方
+print 2**5
+&gt;&gt;&gt; 32
+</code></pre>
+
+<h4>注意浮点数的除法</h4>
+
+<pre><code>print .3/.1
+&gt;&gt;&gt; 2.9999999999999996
+print .3//.1
+&gt;&gt;&gt; 2.0
+</code></pre>
+
+<h4>数值比较</h4>
+
+<pre><code>x = 2
+if 3 &gt; x &gt; 1:
+ print x
+&gt;&gt;&gt; 2
+if 1 &lt; x &gt; 0:
+ print x
+&gt;&gt;&gt; 2
+</code></pre>
+
+<h4>同时迭代两个列表</h4>
+
+<pre><code>nfc = ['Packers', '49ers']
+afc = ['Ravens', 'Patriots']
+for teama, teamb in zip(nfc, afc)
+ print teama + " vs. " + teamb
+&gt;&gt;&gt; Packers vs. Ravens
+&gt;&gt;&gt; 49ers vs. Patriots
+</code></pre>
+
+<h4>带索引的列表迭代</h4>
+
+<pre><code>teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for index, team in enumerate(teams):
+ print index, team
+&gt;&gt;&gt; 0 Packers
+&gt;&gt;&gt; 1 49ers
+&gt;&gt;&gt; 2 Ravens
+&gt;&gt;&gt; 3 Patriots
+</code></pre>
+
+<h4>列表推导式</h4>
+
+<p> 已知一个列表,我们可以刷选出偶数列表方法</p>
+
+<pre><code>numbers = [1,2,3,4,5]
+even = [number for number in numbers if number%2 == 0]
+</code></pre>
+
+<h4>字典推导</h4>
+
+<p> 和列表推导类似</p>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print {key: value for value, key in enumerate(teams)}
+&gt;&gt;&gt; {'49ers': 1, 'Ravens': 2, 'Patriots': 3, 'Packers': 0}
+</code></pre>
+
+<h4>初始化列表的值</h4>
+
+<pre><code>items = [0]*3
+print items
+&gt;&gt;&gt; [0, 0, 0]
+</code></pre>
+
+<h4>列表转换为字符串</h4>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print ", ".join(teams)
+&gt;&gt;&gt; 'Packers, 49ers, Ravens, Patriots'
+</code></pre>
+
+<h4>从字典中获取元素</h4>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+try:
+ is_admin = data['admin']
+except KeyError:
+ is_admin = False
+</code></pre>
+
+<p> 替换成这样:</p>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+is_admin = data.get('admin', False)
+</code></pre>
+
+<h4>获取列表的子集</h4>
+
+<pre><code>x= [1,2,3,4,5]
+# 前3个
+print x[:3]
+&gt;&gt;&gt; [1, 2, 3]
+# 中间4个
+print x[1:5]
+&gt;&gt;&gt; [2, 3, 4, 5]
+# 最后3个
+print x[3:]
+&gt;&gt;&gt; [4, 5, 6]
+# 奇数项
+print x[::2]
+&gt;&gt; [1, 3, 5]
+# 偶数项
+print x[1::2]
+&gt;&gt; [2, 4, 6]
+</code></pre>
+
+<h4>60个字符解决FizzBuzz</h4>
+
+<p> 写一个程序,打印数字1到100,3的倍数打印“Fizz”来替换这个数,5的倍数打印“Buzz”,对于既是3的倍数又是5的倍数的数字打印“FizzBuzz”</p>
+
+<pre><code>for x in range(101):print'fizz'[x%3*4::]+'buzz'[x%5*4::]or x
+</code></pre>
+
+<h4>集合</h4>
+
+<pre><code>from collections import Counter
+print Counter("hello")
+&gt;&gt;&gt; Counter({'1': 2, 'h': 1, 'e': 1, 'o': 1})
+</code></pre>
+
+<h4>迭代工具</h4>
+
+<p> 和collections库一样,还有一个库叫itertools,对某些问题真能高效地解决。其中一个用例是查找所有组合,他能告诉你在一个组中元素的所有不能的组合方式</p>
+
+<pre><code>from itertools import combinations
+teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for game in combinations(teams, 2):
+ print game
+&gt;&gt;&gt; ('Packers', '49ers')
+&gt;&gt;&gt; ('Packers', 'Ravens')
+&gt;&gt;&gt; ('Packers', 'Patriots')
+&gt;&gt;&gt; ('49ers', 'Ravens')
+&gt;&gt;&gt; ('49ers', 'Patriots')
+&gt;&gt;&gt; ('Ravens', 'Patriots')
+</code></pre>
+
+<h4>False == True</h4>
+
+<pre><code>False = True
+if False:
+ print "Hello"
+else:
+ print "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+</div>
+
+
+ <footer>
+ <p class="meta">
+
+
+
+<span class="byline author vcard">Posted by <span class="fn">Mike Gao</span></span>
+
+
+
+
+
+
+
+
+
+
+
+
+
+<time datetime="2013-01-29T10:42:00+08:00" pubdate data-updated="true">Jan 29<span>th</span>, 2013</time>
+
+
+<span class="categories">
+
+ <a class='category' href='/blog/categories/python/'>python</a>
+
+</span>
+
+
+ </p>
+
+ <div class="sharing">
+
+ <a href="http://twitter.com/share" class="twitter-share-button" data-url="http://mikegao.github.com/blog/beginner-of-python/" data-via="" data-counturl="http://mikegao.github.com/blog/beginner-of-python/" >Tweet</a>
+
+
+
+</div>
+
+
+ <p class="meta">
+
+ <a class="basic-alignment left" href="/blog/hello-world/" title="Previous Post: Hello World">&laquo; Hello World</a>
+
+
+ </p>
+ </footer>
+</article>
+
+</div>
+
+<aside class="sidebar">
+
+
+
+
+
+
+<section>
+ <ul id="recent_posts">
+ <li class="post">
+ <a href="http://mikegao.github.com" alt="Home"><img src="/images/Home.png"></a>
+ <a href="http://mikegao.github.com/archives/" alt="Archives"><img src="/images/Calendar.png"></a>
+ <a href="mailto:mike.gao0611@gmail.com" alt="E-Mail"><img src="/images/Envelope.png"></a>
+ <a href="http://mikegao.github.com/atom.xml" alt="subscribe feed"><img src="/images/rss_big.png"></a>
+ </li>
+ </ul>
+</section>
+<section>
+ <h1>About Me</h1>
+ <p>A rubyer, Apple User</p>
+</section>
+<section>
+ <h1>Recent Posts</h1>
+ <ul id="recent_posts">
+
+ <li class="post">
+ <a href="/blog/beginner-of-python/">Beginner_Of_Python</a>
+ </li>
+
+ <li class="post">
+ <a href="/blog/hello-world/">Hello World</a>
+ </li>
+
+ </ul>
+</section>
+
+
+</aside>
+
+
+ </div>
+ </div>
+ <footer role="contentinfo"><p>
+ Copyright &copy; 2013 - Mike Gao -
+ <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
+</p>
+
+</footer>
+
+
+
+
+
+
+
+
+ <script type="text/javascript">
+ (function(){
+ var twitterWidgets = document.createElement('script');
+ twitterWidgets.type = 'text/javascript';
+ twitterWidgets.async = true;
+ twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
+ document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
+ })();
+ </script>
+
+
+
+
+
+</body>
+</html>
View
216 blog/categories/python/atom.xml
@@ -0,0 +1,216 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+ <title><![CDATA[Category: python | Mike Tech]]></title>
+ <link href="http://mikegao.github.com/blog/categories/python/atom.xml" rel="self"/>
+ <link href="http://mikegao.github.com/"/>
+ <updated>2013-01-29T14:00:47+08:00</updated>
+ <id>http://mikegao.github.com/</id>
+ <author>
+ <name><![CDATA[Mike Gao]]></name>
+ <email><![CDATA[mike.gao0611@gmail.com]]></email>
+ </author>
+ <generator uri="http://octopress.org/">Octopress</generator>
+
+
+ <entry>
+ <title type="html"><![CDATA[Beginner_Of_Python]]></title>
+ <link href="http://mikegao.github.com/blog/beginner-of-python/"/>
+ <updated>2013-01-29T10:42:00+08:00</updated>
+ <id>http://mikegao.github.com/blog/beginner-of-python</id>
+ <content type="html"><![CDATA[<h4>变量交换</h4>
+
+<pre><code>x = 6
+y = 5
+
+x, y = y, x
+print x
+&gt;&gt;&gt; 5
+print y
+&gt;&gt;&gt; 6
+</code></pre>
+
+<h4>if 语句再行内</h4>
+
+<pre><code>print "Hello" if True else "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+
+<h4>连接</h4>
+
+<p> 下面的最后一种方式在绑定两个不同类型的对象时显得很cool</p>
+
+<pre><code>nfc = ["Packers", "49ers"]
+afc = ["Ravens", "Patriots"]
+print nfc + afc
+&gt;&gt;&gt; ['Packers', '49ers', 'Ravens', 'Patriots']
+
+print str(1) + " world"
+&gt;&gt;&gt; 1 world
+
+pring 1, "world"
+&gt;&gt;&gt; 1 world
+
+print nfc, 1
+&gt;&gt;&gt; ['Packers', '49ers'] 1
+</code></pre>
+
+<h4>数字技巧</h4>
+
+<pre><code># 除后向下取整
+print 5.0//2
+&gt;&gt;&gt; 2
+# 2的5次方
+print 2**5
+&gt;&gt;&gt; 32
+</code></pre>
+
+<h4>注意浮点数的除法</h4>
+
+<pre><code>print .3/.1
+&gt;&gt;&gt; 2.9999999999999996
+print .3//.1
+&gt;&gt;&gt; 2.0
+</code></pre>
+
+<h4>数值比较</h4>
+
+<pre><code>x = 2
+if 3 &gt; x &gt; 1:
+ print x
+&gt;&gt;&gt; 2
+if 1 &lt; x &gt; 0:
+ print x
+&gt;&gt;&gt; 2
+</code></pre>
+
+<h4>同时迭代两个列表</h4>
+
+<pre><code>nfc = ['Packers', '49ers']
+afc = ['Ravens', 'Patriots']
+for teama, teamb in zip(nfc, afc)
+ print teama + " vs. " + teamb
+&gt;&gt;&gt; Packers vs. Ravens
+&gt;&gt;&gt; 49ers vs. Patriots
+</code></pre>
+
+<h4>带索引的列表迭代</h4>
+
+<pre><code>teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for index, team in enumerate(teams):
+ print index, team
+&gt;&gt;&gt; 0 Packers
+&gt;&gt;&gt; 1 49ers
+&gt;&gt;&gt; 2 Ravens
+&gt;&gt;&gt; 3 Patriots
+</code></pre>
+
+<h4>列表推导式</h4>
+
+<p> 已知一个列表,我们可以刷选出偶数列表方法</p>
+
+<pre><code>numbers = [1,2,3,4,5]
+even = [number for number in numbers if number%2 == 0]
+</code></pre>
+
+<h4>字典推导</h4>
+
+<p> 和列表推导类似</p>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print {key: value for value, key in enumerate(teams)}
+&gt;&gt;&gt; {'49ers': 1, 'Ravens': 2, 'Patriots': 3, 'Packers': 0}
+</code></pre>
+
+<h4>初始化列表的值</h4>
+
+<pre><code>items = [0]*3
+print items
+&gt;&gt;&gt; [0, 0, 0]
+</code></pre>
+
+<h4>列表转换为字符串</h4>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print ", ".join(teams)
+&gt;&gt;&gt; 'Packers, 49ers, Ravens, Patriots'
+</code></pre>
+
+<h4>从字典中获取元素</h4>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+try:
+ is_admin = data['admin']
+except KeyError:
+ is_admin = False
+</code></pre>
+
+<p> 替换成这样:</p>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+is_admin = data.get('admin', False)
+</code></pre>
+
+<h4>获取列表的子集</h4>
+
+<pre><code>x= [1,2,3,4,5]
+# 前3个
+print x[:3]
+&gt;&gt;&gt; [1, 2, 3]
+# 中间4个
+print x[1:5]
+&gt;&gt;&gt; [2, 3, 4, 5]
+# 最后3个
+print x[3:]
+&gt;&gt;&gt; [4, 5, 6]
+# 奇数项
+print x[::2]
+&gt;&gt; [1, 3, 5]
+# 偶数项
+print x[1::2]
+&gt;&gt; [2, 4, 6]
+</code></pre>
+
+<h4>60个字符解决FizzBuzz</h4>
+
+<p> 写一个程序,打印数字1到100,3的倍数打印“Fizz”来替换这个数,5的倍数打印“Buzz”,对于既是3的倍数又是5的倍数的数字打印“FizzBuzz”</p>
+
+<pre><code>for x in range(101):print'fizz'[x%3*4::]+'buzz'[x%5*4::]or x
+</code></pre>
+
+<h4>集合</h4>
+
+<pre><code>from collections import Counter
+print Counter("hello")
+&gt;&gt;&gt; Counter({'1': 2, 'h': 1, 'e': 1, 'o': 1})
+</code></pre>
+
+<h4>迭代工具</h4>
+
+<p> 和collections库一样,还有一个库叫itertools,对某些问题真能高效地解决。其中一个用例是查找所有组合,他能告诉你在一个组中元素的所有不能的组合方式</p>
+
+<pre><code>from itertools import combinations
+teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for game in combinations(teams, 2):
+ print game
+&gt;&gt;&gt; ('Packers', '49ers')
+&gt;&gt;&gt; ('Packers', 'Ravens')
+&gt;&gt;&gt; ('Packers', 'Patriots')
+&gt;&gt;&gt; ('49ers', 'Ravens')
+&gt;&gt;&gt; ('49ers', 'Patriots')
+&gt;&gt;&gt; ('Ravens', 'Patriots')
+</code></pre>
+
+<h4>False == True</h4>
+
+<pre><code>False = True
+if False:
+ print "Hello"
+else:
+ print "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+]]></content>
+ </entry>
+
+</feed>
View
168 blog/categories/python/index.html
@@ -0,0 +1,168 @@
+
+<!DOCTYPE html>
+<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
+<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
+<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
+<head>
+ <meta charset="utf-8">
+ <title>Category: python - Mike Tech</title>
+ <meta name="author" content="Mike Gao">
+
+
+ <meta name="description" content="Category: python">
+
+
+ <!-- http://t.co/dKP3o1e -->
+ <meta name="HandheldFriendly" content="True">
+ <meta name="MobileOptimized" content="320">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+
+
+ <link rel="canonical" href="http://mikegao.github.comblog/categories/python/">
+ <link href="/favicon.png" rel="icon">
+ <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
+ <script src="/javascripts/modernizr-2.0.js"></script>
+ <script src="/javascripts/ender.js"></script>
+ <script src="/javascripts/octopress.js" type="text/javascript"></script>
+ <link href="/atom.xml" rel="alternate" title="Mike Tech" type="application/atom+xml">
+ <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
+<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+
+
+
+</head>
+
+<body >
+ <header role="banner"><hgroup>
+ <h1><a href="/">Mike Tech</a></h1>
+
+</hgroup>
+
+</header>
+ <nav role="navigation"><ul class="subscription" data-subscription="rss">
+ <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
+
+</ul>
+
+<form action="http://google.com/search" method="get">
+ <fieldset role="search">
+ <input type="hidden" name="q" value="site:mikegao.github.com" />
+ <input class="search" type="text" name="q" results="0" placeholder="Search"/>
+ </fieldset>
+</form>
+
+<ul class="main-navigation">
+ <li><a href="/">Blog</a></li>
+ <li><a href="/blog/archives">Archives</a></li>
+</ul>
+
+</nav>
+ <div id="main">
+ <div id="content">
+ <div>
+<article role="article">
+
+ <header>
+ <h1 class="entry-title">Category: Python</h1>
+
+ </header>
+
+ <div id="blog-archives" class="category">
+
+
+
+
+ <h2>2013</h2>
+
+<article>
+
+<h1><a href="/blog/beginner-of-python/">Beginner_Of_Python</a></h1>
+<time datetime="2013-01-29T10:42:00+08:00" pubdate><span class='month'>Jan</span> <span class='day'>29</span> <span class='year'>2013</span></time>
+
+<footer>
+ <span class="categories">posted in <a class='category' href='/blog/categories/python/'>python</a></span>
+</footer>
+
+
+</article>
+
+</div>
+
+
+</article>
+
+</div>
+
+<aside class="sidebar">
+
+
+
+
+
+
+<section>
+ <ul id="recent_posts">
+ <li class="post">
+ <a href="http://mikegao.github.com" alt="Home"><img src="/images/Home.png"></a>
+ <a href="http://mikegao.github.com/archives/" alt="Archives"><img src="/images/Calendar.png"></a>
+ <a href="mailto:mike.gao0611@gmail.com" alt="E-Mail"><img src="/images/Envelope.png"></a>
+ <a href="http://mikegao.github.com/atom.xml" alt="subscribe feed"><img src="/images/rss_big.png"></a>
+ </li>
+ </ul>
+</section>
+<section>
+ <h1>About Me</h1>
+ <p>A rubyer, Apple User</p>
+</section>
+<section>
+ <h1>Recent Posts</h1>
+ <ul id="recent_posts">
+
+ <li class="post">
+ <a href="/blog/beginner-of-python/">Beginner_Of_Python</a>
+ </li>
+
+ <li class="post">
+ <a href="/blog/hello-world/">Hello World</a>
+ </li>
+
+ </ul>
+</section>
+
+
+</aside>
+
+
+ </div>
+ </div>
+ <footer role="contentinfo"><p>
+ Copyright &copy; 2013 - Mike Gao -
+ <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
+</p>
+
+</footer>
+
+
+
+
+
+
+
+
+ <script type="text/javascript">
+ (function(){
+ var twitterWidgets = document.createElement('script');
+ twitterWidgets.type = 'text/javascript';
+ twitterWidgets.async = true;
+ twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
+ document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
+ })();
+ </script>
+
+
+
+
+
+</body>
+</html>
View
6 blog/hello-world/index.html
@@ -131,6 +131,8 @@ <h1 class="entry-title">Hello World</h1>
<p class="meta">
+ <a class="basic-alignment right" href="/blog/beginner-of-python/" title="Next Post: Beginner_Of_Python">Beginner_Of_Python &raquo;</a>
+
</p>
</footer>
</article>
@@ -163,6 +165,10 @@ <h1 class="entry-title">Hello World</h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/beginner-of-python/">Beginner_Of_Python</a>
+ </li>
+
+ <li class="post">
<a href="/blog/hello-world/">Hello World</a>
</li>
View
239 index.html
@@ -9,8 +9,12 @@
<meta name="author" content="Mike Gao">
- <meta name="description" content=" 终于搞好了OctPress On Git Page! 继续Blog之旅
-">
+ <meta name="description" content="变量交换 x = 6
+y = 5 x, y = y, x
+print x &gt;&gt;&gt; 5
+print y
+&gt;&gt;&gt; 6 if 语句再行内 print "Hello" if True else "World"
+&gt;&gt;&gt; Hello 连接 &hellip;">
<!-- http://t.co/dKP3o1e -->
@@ -69,6 +73,233 @@
<header>
+ <h1 class="entry-title"><a href="/blog/beginner-of-python/">Beginner_Of_Python</a></h1>
+
+
+ <p class="meta">
+
+
+
+
+
+
+
+
+
+
+
+
+<time datetime="2013-01-29T10:42:00+08:00" pubdate data-updated="true">Jan 29<span>th</span>, 2013</time>
+
+ </p>
+
+ </header>
+
+
+ <div class="entry-content"><h4>变量交换</h4>
+
+<pre><code>x = 6
+y = 5
+
+x, y = y, x
+print x
+&gt;&gt;&gt; 5
+print y
+&gt;&gt;&gt; 6
+</code></pre>
+
+<h4>if 语句再行内</h4>
+
+<pre><code>print "Hello" if True else "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+
+<h4>连接</h4>
+
+<p> 下面的最后一种方式在绑定两个不同类型的对象时显得很cool</p>
+
+<pre><code>nfc = ["Packers", "49ers"]
+afc = ["Ravens", "Patriots"]
+print nfc + afc
+&gt;&gt;&gt; ['Packers', '49ers', 'Ravens', 'Patriots']
+
+print str(1) + " world"
+&gt;&gt;&gt; 1 world
+
+pring 1, "world"
+&gt;&gt;&gt; 1 world
+
+print nfc, 1
+&gt;&gt;&gt; ['Packers', '49ers'] 1
+</code></pre>
+
+<h4>数字技巧</h4>
+
+<pre><code># 除后向下取整
+print 5.0//2
+&gt;&gt;&gt; 2
+# 2的5次方
+print 2**5
+&gt;&gt;&gt; 32
+</code></pre>
+
+<h4>注意浮点数的除法</h4>
+
+<pre><code>print .3/.1
+&gt;&gt;&gt; 2.9999999999999996
+print .3//.1
+&gt;&gt;&gt; 2.0
+</code></pre>
+
+<h4>数值比较</h4>
+
+<pre><code>x = 2
+if 3 &gt; x &gt; 1:
+ print x
+&gt;&gt;&gt; 2
+if 1 &lt; x &gt; 0:
+ print x
+&gt;&gt;&gt; 2
+</code></pre>
+
+<h4>同时迭代两个列表</h4>
+
+<pre><code>nfc = ['Packers', '49ers']
+afc = ['Ravens', 'Patriots']
+for teama, teamb in zip(nfc, afc)
+ print teama + " vs. " + teamb
+&gt;&gt;&gt; Packers vs. Ravens
+&gt;&gt;&gt; 49ers vs. Patriots
+</code></pre>
+
+<h4>带索引的列表迭代</h4>
+
+<pre><code>teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for index, team in enumerate(teams):
+ print index, team
+&gt;&gt;&gt; 0 Packers
+&gt;&gt;&gt; 1 49ers
+&gt;&gt;&gt; 2 Ravens
+&gt;&gt;&gt; 3 Patriots
+</code></pre>
+
+<h4>列表推导式</h4>
+
+<p> 已知一个列表,我们可以刷选出偶数列表方法</p>
+
+<pre><code>numbers = [1,2,3,4,5]
+even = [number for number in numbers if number%2 == 0]
+</code></pre>
+
+<h4>字典推导</h4>
+
+<p> 和列表推导类似</p>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print {key: value for value, key in enumerate(teams)}
+&gt;&gt;&gt; {'49ers': 1, 'Ravens': 2, 'Patriots': 3, 'Packers': 0}
+</code></pre>
+
+<h4>初始化列表的值</h4>
+
+<pre><code>items = [0]*3
+print items
+&gt;&gt;&gt; [0, 0, 0]
+</code></pre>
+
+<h4>列表转换为字符串</h4>
+
+<pre><code>teams = ['Packers', '49ers', 'Ravens', 'Patriots']
+print ", ".join(teams)
+&gt;&gt;&gt; 'Packers, 49ers, Ravens, Patriots'
+</code></pre>
+
+<h4>从字典中获取元素</h4>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+try:
+ is_admin = data['admin']
+except KeyError:
+ is_admin = False
+</code></pre>
+
+<p> 替换成这样:</p>
+
+<pre><code>data = {'user': 1, 'name': 'Max', 'three': 4}
+is_admin = data.get('admin', False)
+</code></pre>
+
+<h4>获取列表的子集</h4>
+
+<pre><code>x= [1,2,3,4,5]
+# 前3个
+print x[:3]
+&gt;&gt;&gt; [1, 2, 3]
+# 中间4个
+print x[1:5]
+&gt;&gt;&gt; [2, 3, 4, 5]
+# 最后3个
+print x[3:]
+&gt;&gt;&gt; [4, 5, 6]
+# 奇数项
+print x[::2]
+&gt;&gt; [1, 3, 5]
+# 偶数项
+print x[1::2]
+&gt;&gt; [2, 4, 6]
+</code></pre>
+
+<h4>60个字符解决FizzBuzz</h4>
+
+<p> 写一个程序,打印数字1到100,3的倍数打印“Fizz”来替换这个数,5的倍数打印“Buzz”,对于既是3的倍数又是5的倍数的数字打印“FizzBuzz”</p>
+
+<pre><code>for x in range(101):print'fizz'[x%3*4::]+'buzz'[x%5*4::]or x
+</code></pre>
+
+<h4>集合</h4>
+
+<pre><code>from collections import Counter
+print Counter("hello")
+&gt;&gt;&gt; Counter({'1': 2, 'h': 1, 'e': 1, 'o': 1})
+</code></pre>
+
+<h4>迭代工具</h4>
+
+<p> 和collections库一样,还有一个库叫itertools,对某些问题真能高效地解决。其中一个用例是查找所有组合,他能告诉你在一个组中元素的所有不能的组合方式</p>
+
+<pre><code>from itertools import combinations
+teams = ["Packers", "49ers", "Ravens", "Patriots"]
+for game in combinations(teams, 2):
+ print game
+&gt;&gt;&gt; ('Packers', '49ers')
+&gt;&gt;&gt; ('Packers', 'Ravens')
+&gt;&gt;&gt; ('Packers', 'Patriots')
+&gt;&gt;&gt; ('49ers', 'Ravens')
+&gt;&gt;&gt; ('49ers', 'Patriots')
+&gt;&gt;&gt; ('Ravens', 'Patriots')
+</code></pre>
+
+<h4>False == True</h4>
+
+<pre><code>False = True
+if False:
+ print "Hello"
+else:
+ print "World"
+&gt;&gt;&gt; Hello
+</code></pre>
+</div>
+
+
+
+
+ </article>
+
+
+ <article>
+
+ <header>
+
<h1 class="entry-title"><a href="/blog/hello-world/">Hello World</a></h1>
@@ -133,6 +364,10 @@ <h1 class="entry-title"><a href="/blog/hello-world/">Hello World</a></h1>
<ul id="recent_posts">
<li class="post">
+ <a href="/blog/beginner-of-python/">Beginner_Of_Python</a>
+ </li>
+
+ <li class="post">
<a href="/blog/hello-world/">Hello World</a>
</li>
View
10 sitemap.xml
@@ -5,20 +5,24 @@
<lastmod>2013-01-29T10:25:04+08:00</lastmod>
</url>
<url>
+ <loc>http://mikegao.github.com/blog/beginner-of-python/</loc>
+ <lastmod>2013-01-29T14:00:46+08:00</lastmod>
+ </url>
+ <url>
<loc>http://mikegao.github.com/about/</loc>
<lastmod>2013-01-29T10:19:23+08:00</lastmod>
</url>
<url>
<loc>http://mikegao.github.com/archives/</loc>
- <lastmod>2013-01-29T10:25:04+08:00</lastmod>
+ <lastmod>2013-01-29T14:00:46+08:00</lastmod>
</url>
<url>
<loc>http://mikegao.github.com/blog/archives/</loc>
- <lastmod>2013-01-29T10:25:04+08:00</lastmod>
+ <lastmod>2013-01-29T14:00:46+08:00</lastmod>
</url>
<url>
<loc>http://mikegao.github.com/</loc>
- <lastmod>2013-01-29T10:25:04+08:00</lastmod>
+ <lastmod>2013-01-29T14:00:46+08:00</lastmod>
</url>
<url>
<loc>http://mikegao.github.com/robots.txt</loc>

0 comments on commit 3e83942

Please sign in to comment.