• 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. CSS之详解:active选择器

    Active的一段话 active的英文解释为"积极的",表现在鼠标上就是点击的意思.关于active选择器最多的示例恐怕就是应用在链接上面的,然而打开链接是一个一瞬间的动作,这不 ...

  2. jQuery仿京东无限级菜单HoverTree

    官方网址:http://keleyi.com/jq/hovertree/ 效果图: 看了上面效果图,你或许已经明白为什么是仿京东菜单.如果还不明白,请访问http://list.jd.com/list ...

  3. 【经验之谈】前端面试知识点总结(CSS相关)——附答案

    目录 二.CSS部分 1.解释一下CSS的盒子模型? 2.请你说说CSS选择器的类型有哪些,并举几个例子说明其用法? 3.请你说说CSS有什么特殊性?(优先级.计算特殊值) 4.要动态改变层中内容可以 ...

  4. 浅谈TypeScript

    TypeScript为JavaScript的超集(ECMAScript6), 这个语言添加了基于类的面向对象编程.TypeScript作为JavaScript很大的一个语法糖,本质上是类似于css的l ...

  5. This version of android studio is incompatible with the gradle version used.Try disabling the instant run解决办法

    今天打开android studio又碰到一个奇怪的问题:This version of android studio is incompatible with the gradle version ...

  6. 操作系统开发系列—12.a.从Loader到内核 ●

    Loader要做两项工作,我们先来做第一项,把内核加载到内存: 1.加载内核到内存. 2.跳入保护模式. 首先编译无内核时: nasm boot.asm -o boot.bin nasm loader ...

  7. 使用AndroidStudio进行NDK开发简单配置

    1. 准备工作 在实际写代码之前,首先我们还是需要做一些准备工作: 下载NDK开发包:Android官方下载页面 配置系统环境变量 下载好NDK开发包之后,直接解压到任意目录,然后需要配置一下系统环境 ...

  8. 运维之Centos apache vsftpd配置

    安装Apache yum install httpd -y chkconfig httpd on service httpd start 配置一下iptables iptables -I INPUT ...

  9. post请求报文

    POST /02_WEB_HTTP/index.html HTTP/1.1 Accept: application/x-ms-application, image/jpeg, application/ ...

  10. yii2解决百度编辑器umeditor图片上传问题

    作者:白狼 出处:http://www.manks.top/article/yii2_umeditor_upload本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原 ...