• 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. JSCapture – 基于 HTML5 实现的屏幕捕捉库

    JSCapture 是用纯 JavaScript 和 HTML5 实现的屏幕捕捉库.它可以让从您的浏览器中截图和记录在桌面的视频.JSCapture 使用 getUserMedia 来实现屏幕捕获.目 ...

  2. git node(&npm)安装

    1.git 下载地址:https://git-scm.com/download/win 2.node 下载地址:https://nodejs.org/en/download/ 安装node会自带npm ...

  3. div水平居中

    1.先给它外层的div定位并left:position:absolute;left:50%; 2.获取当前元素div的宽度,并除以2 3.改变它的css:margin-left:-(获取当前元素div ...

  4. HTML <hr /> 标签 在页面中创建一条水平线

    一,定义和用法 <hr /> 标签在 HTML 页面中创建一条水平线. 水平分隔线(horizontal rule)可以在视觉上将文档分隔成各个部分. 二,HTML 与 XHTML 之间的 ...

  5. BP神经网络实现

    # -*- coding: utf-8 -*- # -------------------------------------------------------------------------- ...

  6. 分分钟学会系列:mac地址泛洪攻击实验

    一.实验目的: 通过实战深入理解mac地址泛洪攻击的原理. 二.实验原理: 交换机中有一张非常重要的表,叫做mac表,这个表是一个硬件组成的表,主要是完成快速转发.mac表有大小限制,不同的交换机的m ...

  7. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q6-Q8)

    Question 6  You are designing a SharePoint 2010 solution that allows users to enter address informat ...

  8. [Android]AndroidInject增加sqlite3数据库映射注解(ORM)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3623050.html AndroidInject项目是我写的一 ...

  9. iOS通用的MVC模式项目框架MobileProject

    最近项目比较不赶的情况下,决定把一些通用.常用的内容集成在一个项目框架中,意在新项目中可以快速搭建:其实经过几个项目后,总是有一些重复的创建工作,可以使用本项目的内容直接进行开发:采用的是MVC的分层 ...

  10. 一次对MKMapView的性能优化

    一次对MKMapView的性能优化 前言 最近做的项目主要是LBS这块 主打成员定位功能 我们的UI设计是这样的 乍一看上去是挺好挺美观的 不同的人会显示不同的头像 可是当人扎堆的时候 问题就来了 当 ...