[Notes] Learn Python2.7 From Python Tutorial
- 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的更多相关文章
- [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 ...
- 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 ...
- [译]The Python Tutorial#2. Using the Python Interpreter
[译]The Python Tutorial#Using the Python Interpreter 2.1 Invoking the Interpreter Python解释器通常安装在目标机器的 ...
- Python Tutorial 学习(八)--Errors and Exceptions
Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一 ...
- Python Tutorial 学习(六)--Modules
6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知 ...
- [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II
[译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...
- [译]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模块为与操作系统 ...
- [译]The Python Tutorial#12. Virtual Environments and Packages
[译]The Python Tutorial#Virtual Environments and Packages 12.1 Introduction Python应用经常使用不属于标准库的包和模块.应 ...
- [译]The Python Tutorial#1. Whetting Your Appetite
[译]The Python Tutorial#Whetting Your Appetite 1. Whetting Your Appetite 如果你需要使用计算机做很多工作,最终会发现很多任务需要自 ...
随机推荐
- scrollify.js 鼠标滚动
在线实例 实例演示 使用方法 <! doctype html> <html> <head> <script> $(function() { $.scro ...
- WPF的ComboBox 数据模板自定义
WPF的ComboBox 有些时候不能满足用户需求,需要对数据内容和样式进行自定义,下面就简要介绍一下用数据模板(DataTemplate)的方式对ComboBox 内容进行定制: 原型设计如下: 步 ...
- SQLServer表内自关联级联删除
今天处理SQLServer级联删除遇到了很蛋疼的事. SQLServer 不支持表内自关联级联删除,而MySql和Oracle却支持. 貌似原因是SQLServer 会产生循环级联,就不给这样弄.所以 ...
- Sql Server Always On主库与附库遇到的问题
使用Always On的时候永远要记住只有一个主数据库可写,如果写的话要不在监听节点上做写的操作,要不只在主数据库上写的操作不然只读库无法读写
- AVAudioSession初探
根据文档,AudioSession规定了app和系统音频行为交互的规范,一个app只有一个AudioSession的单例. app通过设置自己AudioSession的单例的属性来告诉系统自身想达到的 ...
- 遍历collection
链接 遍历NSArray 正向遍历 for (id object in array) 反向遍历 for (id object in [array reverseObjectEnumerator]) 如 ...
- 折腾一天的WordPress
自从昨天开始要写博客,在网上找了找大家都比较推崇著名的WordPress,所以自己就闲来无事要坐下测试弄一个,不弄不知道,一弄折磨人啊,公司的破网直接想让我崩溃,所以这一天就在这搭建环境中度过,不过值 ...
- Android SurfaceView的生命周期
本文利用SurfaceView来实现视频的播放 本文地址:http://www.cnblogs.com/wuyudong/p/5851156.html,转载请注明源地址. 在main.xml布局文件添 ...
- mac PHP配置
apache默认路径配置方法 apache的配置 apache已经自带了,只需如下三个命令就可以了. 开启apache服务 sudo apachectl start 停止apache服务 sudo ...
- Zend Studio 12 安装及破解
安装: 1.下载最新版本Zend Studio:http://downloads.zend.com/studio-eclipse/12.0.0/ZendStudio-12.0.0-win32.win3 ...