[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 如果你需要使用计算机做很多工作,最终会发现很多任务需要自 ...
随机推荐
- CountUp.js – 让数字以非常有趣的动画方式显示
CountUp.js 无依赖的.轻量级的 JavaScript 类,可以用来快速创建以一种更有趣的动画方式显示数值数据.尽管它的名字叫 countUp,但其实可以在两个方向进行变化,这是根据你传递的 ...
- 20款免费响应式的 HTML5 网站模板下载
今天这篇文章给大家带来的是20款免费响应式的 HTML5 网站模板,大家可以借助这些优秀的网站模板创建自己的优秀网站.响应式(Responsive Design)设计的目标是要让产品界面能够响应用户的 ...
- Session Storage、Cache Storage
Session Storage sessionStorage用于本地存储一个会话(session)的数据,这些数据只有在同一个会话中的页面才能访问并且当会话结束后数据也随之销毁(浏览器关闭).因此se ...
- javascript --- 事件冒泡与事件捕获
事件冒泡与事件捕获 事件冒泡和事件捕获分别由微软和网景公司提出,这两个概念都是为了解决页面中事件流(事件发生顺序)的问题.考虑下面这段代码,就不写html->head,body之类的代码了,自行 ...
- chrome developer tool—— 断点调试篇
断点,调试器的功能之一,可以让程序中断在需要的地方,从而方便其分析.也可以在一次调试中设置断点,下一次只需让程序自动运行到设置断点位置,便可在上次设置断点的位置中断下来,极大的方便了操作,同时节省了时 ...
- 利用Ajax增删改Sharepoint List Item
在使用一个工具的是想要在本地的HTML文件或者JS,修改Sharepoint List中的数据. 如下是找到的方法.不知道还有其他方法没.IE中可以使用.记得加载Jquery. 如果是Chrome 浏 ...
- 编译Android系统源码(高通平台)
在Android源码根目录执行下面命令 source build/envsetup.sh choosecombo make –j4 其他命令(首先需要在android源码根目录执行source bui ...
- Masonry(AutoLayout)的使用
Masonry 仍然在维持. 如果使用 Swift 开发, 建议使用 SnapKit. Masonry 以一种简便可读的代码实现子控件自动布局 ,甚至可以实现一些动画,是一中轻量级的框架. Mason ...
- jetty for linux 启用日志
jetty7.8 文档 :https://wiki.eclipse.org/Jetty jetty9 文档: http://www.eclipse.org/jetty/documentation/cu ...
- 1.6 基础知识——GP2.5 培训(Training)
摘要: 实际上做任何项目总会缺失各种技能,培训特别是未雨绸缪的培训就显得很必要了! 正文: GP2.5 Traing the people performing or supporting XXX p ...