• I have planed to learn Python for many times.
  • I have started to learn Python for many times .
  • However, I can't use it fluently up to now.
  • Now I know I was wrong.
  • I just tried to remember the syntax and took notes on paper with little practice.
  • Now I print the Python Tutorial and learn it by using it.
  • Practice. Practice. Practice.
  • I love Python. It is glamourous.

Here are notes:

# In interactive mode, the last printed expression is assigned to the variable _
>>> price * tax
7.5
>>> price + _
113.0625

# use raw string
>>> print 'C:\some\name'
C:\some
ame
>>> print r'C:\some\name'
C:\some\name

# use triple-quotes:
>>> print """\  #  \ is to prevent  \n
Usage: thingy [OPTIONS]
    -h
    -H hostname
"""

>>> 3 * ('pyth' 'on')
'pythonpythonpython'

# slice
>>> word = 'Python'
>>> word[ :2]
'Pyt'
>>> word[0] = 'J' # error. You can't do this.
>>> len(word)
6

# use Unicode strings.
>>> u'Hello\u0020World!'
u'Hello World'
>>> ur'Hello\\u0020world'
>>> u'Hello\\\\u0020world'

# list
>>> squares = [1, 'abc', 9, 16, 25]
>>> squares[1][1]
'b'
>>> squares.append("abcd")
>>> a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]

# Fibonacci series:
while b < 10:
     print b
     a, b = b, a+b

# Control Flow
# if
if x < 0:
    x = 0
elif x == 0:
    x = 1
else:
    print 'Ok'

# for - 1
words = ['cat', 'window', 'defenestrate']
for w in words:
    print w, len(w)

# for - 2
for w in words[:]:
    if len(w) > 6:
        words.insert(0, w)
# here is a question: I use 'for w in words' while that can't make sense. Why?

>>> range(0, 10, 3)
[0, 3, 6, 9]

a = ['a', 'b', 'c']
for i in range(len(a)):
    print i, a[i]

# you can alse use:
for index, item in enumerate(a):
    print index, item

# break & continue & else on LOOP:
for n in  range(2, 10):
    for x in range(2, n):
        if n % x == 0:
            print n, 'equals', x, '*', n/x
            break
    # The else belongs to the 'for' loop, not the 'if' statement.
    else:
        # loop fell through without finding a factor
        print n, 'is a prime number'

[Notes] Learn Python2.7 From Python Tutorial的更多相关文章

  1. [Python Study Notes] 抉择--Python2.x Or Python 3.x

    In summary : Python 2.x is legacy, Python 3.x is the present and future of the language Python 3.0 w ...

  2. A Complete Tutorial to Learn Data Science with Python from Scratch

    A Complete Tutorial to Learn Data Science with Python from Scratch Introduction It happened few year ...

  3. [译]The Python Tutorial#2. Using the Python Interpreter

    [译]The Python Tutorial#Using the Python Interpreter 2.1 Invoking the Interpreter Python解释器通常安装在目标机器的 ...

  4. Python Tutorial 学习(八)--Errors and Exceptions

    Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一 ...

  5. Python Tutorial 学习(六)--Modules

    6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知 ...

  6. [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II

    [译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...

  7. [译]The Python Tutorial#10. Brief Tour of the Standard Library

    [译]The Python Tutorial#Brief Tour of the Standard Library 10.1 Operating System Interface os模块为与操作系统 ...

  8. [译]The Python Tutorial#12. Virtual Environments and Packages

    [译]The Python Tutorial#Virtual Environments and Packages 12.1 Introduction Python应用经常使用不属于标准库的包和模块.应 ...

  9. [译]The Python Tutorial#1. Whetting Your Appetite

    [译]The Python Tutorial#Whetting Your Appetite 1. Whetting Your Appetite 如果你需要使用计算机做很多工作,最终会发现很多任务需要自 ...

随机推荐

  1. Vue.js 2.0 参考手册.CHM下载

    下载地址 Vue.js 2.0 参考手册.CHM下载链接: http://pan.baidu.com/s/1kVbhd4b 密码: wxfh

  2. 使用虚拟按钮(Ghost Buttons)的25个网站

    2014年已经过去大半年了,我们看到网页设计领域出现新的设计趋势. 虚拟按钮(Ghost Buttons)是指具备基本的按钮形状的透明按钮,但有细实线的边框.有些虚拟钮是互动的,点击之后按钮可能会成为 ...

  3. angularjs 指令—— 绑定策略(@、=、&)

    angularjs 指令—— 绑定策略(@.=.&) 引入主题背景:angular 的指令配置中的template可以直接使用硬编码写相应的代码,不过也可以根据变量,进行动态更新.那么需要用到 ...

  4. 1:时间戳转换成年月日函数,2:url截取参数方法,3:弹窗自定义方法 4:点击按钮加入购物车

    最近一直在使用vue.js来构建项目,先分享一下一些简单可复用的函数. 1:时间戳转换Date.prototype.format = function(fmt){ //author: yumeiqia ...

  5. 原型prototype

    JS对象的比较 由于JS是解释执行的语言,那么代码中出现函数与对象如果重复执行,会创建多个副本 创建一个Person构造函数,要求有name,age,gender,sayHello 代码如下: fun ...

  6. Oracle中用随机数更新字段----将一张表的数据插入另一张表----环境设置

    DECLARE CURSOR recordCursor IS SELECT longitude,latitude FROM WR_WIUST_B_SEC FOR UPDATE; recordRow r ...

  7. CVE: 2014-6271、CVE: 2014-7169 Bash Specially-crafted Environment Variables Code Injection Vulnerability Analysis

    目录 . 漏洞的起因 . 漏洞原理分析 . 漏洞的影响范围 . 漏洞的利用场景 . 漏洞的POC.测试方法 . 漏洞的修复Patch情况 . 如何避免此类漏洞继续出现 1. 漏洞的起因 为了理解这个漏 ...

  8. linux命令学习使用记录

    1.文件批量重命名:把所有.xml文件重命名.txt,第一个参数为文件名中字符串,第二个参数为替换后文件名,第三个为当前目录文件列表 rename .xml .txt *.xml 2.解压不显示过程: ...

  9. 原创:phoenix4.6.0连接hbase1.1.2(不使用phoenix-4.6.0-HBase-1.1-client.jar)

    官网上面的例子是在phoenix-4.6.0-HBase-1.1-client.jar完成的,这个jar包含了phoenix4.6连接hbase1.1.2所有的依赖,真是包罗万象(里面竟然还包括了se ...

  10. Android Actitity的生命周期

    新建项目,MainActivity代码如下: package com.wuyudong.lifecycle; import android.os.Bundle; import android.app. ...