• 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. 类似 Google Tips 页面的卡片式提示和翻转特效

    这款 jQuery 插件用于实现类似 Google Tips 页面的卡片式提示和翻转的交互特效.你可以根据自己的需要定制动画效果参数,定义回调函数来控制行为.因为使用了 CSS3,所以只支持 Chro ...

  2. Hyhyhy – 专业的 HTML5 演示文稿工具

    Hyhyhy 是创建好看的 HTML5 演示文档的工具.它具备很多的特点:支持 Markdown,嵌套幻灯片,数学排版,兼容性,语法高亮,使用 Javascript API ,方便的骨架.它支持 Fi ...

  3. 2015年免费的25款 WordPress 网站模板

    2015年 WordPress 插件和主题的数量继续在增长.这一年,我们可以期待WP主题引入一些新的技术,从背景,自适应响应式图像到从背景图片中提取主色. 本文包含25款最近发布的 WordPress ...

  4. AH00098 pid file overwritten

    错误日志: 由于定义了: <IfModule mpm_winnt_module> ThreadsPerChild 450 MaxConnectionsPerChild 4000 Accep ...

  5. 小白详细讲解快速幂--杭电oj2035-A^B

    Problem Description 求A^B的最后三位数表示的整数.说明:A^B的含义是“A的B次方”  Input 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<= ...

  6. 为什么你找不到优秀的GISer?

    每年的三四月是招聘的黄金时节,故有金三银四的说法.求贤纳才对于处在发展上升期的公司来说,是全年性的常态化工作.只是这俩月市场上求职者数量较别的月份多.基数大了,淘到金子的概率自然会增加.大部分公司的伯 ...

  7. JavaScript学习03 JS函数

    JavaScript学习03 JS函数 函数就是包裹在花括号中的代码块,前面使用了关键词function: function functionName() { 这里是要执行的代码 } 函数参数 函数的 ...

  8. git 新建服务器的版本以及项目的用户

    一, git客户端账号生成 1. git的客户端的公钥生成 ssh-keygen -t rsa -C "test@gmail.com" mac机器会在 /Users/用户/.ssh ...

  9. Android-SQLite版本问题

    1. 用户 重来没有使用过该软件 不存在数据库,我们 1). 自动调用 void onCreate(SQLiteDatabase db) 方法 创建数据库 2).创建 表 , 3).给表插入初始化数据 ...

  10. UISegmentedControl(人物简介)

    效果图 当你点击上面人物名字的时候 ,就可以随意切换人物. 这个很有趣 , 你还可以试着添加音乐播放器 .以及一些别的来完善你想做的. 好吧 , 废话不多说 , 上代码. #import " ...