[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 如果你需要使用计算机做很多工作,最终会发现很多任务需要自 ...
随机推荐
- Dewplayer 音乐播放器
Dewplayer 是一款用于 Web 的轻量级 Flash 音乐播放器.提供有多种样式选择,支持播放列表,并可以通过 JavaScript 接口来控制播放器. 注意事项: 该播放器只支持 mp3 格 ...
- 简洁的jQuery cxMenu 手风琴导航
版本: jQuery v1.7+ jQuery cxMenu v1.2 注意事项: 自动判断是否有子导航,有则显示并不触发链接,无则触发链接. 实例预览 使用方法 载入 JavaScript 文件 & ...
- CSS盒子模型
2016-10-22 <css入门经典>第6章 1.每个HTML元素对应于一个显示盒子,但不是所有的元素都显示在屏幕上. 2.HTML元素显示为CSS显示盒子的真正方法称为"可视 ...
- 编写更加稳定/可读的javascript代码
每个人都有自己的编程风格,也无可避免的要去感受别人的编程风格--修改别人的代码."修改别人的代码"对于我们来说的一件很痛苦的事情.因为有些代码并不是那么容易阅读.可维护的,让另一个 ...
- JSOM 中对各种字段操作
function createListItem() { var clientContext = new SP.ClientContext(_spPageContextInfo.siteAbs ...
- IDA来Patch android的so文件
在上文中,我们通过分析定位到sub_130C()这个函数有很大可能性是用来做反调试检测的,并且作者开了一个新的线程,并且用了一个while来不断执行sub_130C()这个函数,所以说我们每次手动的修 ...
- iOS 跳转到App Store下载或评论
//跳转到app在AppStore页面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString string ...
- 关于Android四大组件的学习总结
Activity Android应用的用户界面是由Activity类管理的.和其他组件一样,Activity会用一系列生命周期回调函数通知当前的状态. 生命周期 Activity的四种状态 1.运行状 ...
- Scrum Master 面试题 – 你必须知道的22个Scrum基础知识
以下的22个问题基本上涵盖了Scrum所涉及的内容,如果你能够正确回答出所有问题,那么你已经具备了作为一名Scrum Master的基本素质:当然,作为一名合格的Scrum Master,更重要的是你 ...
- WPF学习之路(二) XAML(续)
属性 简单属性 前面用到的Width/Height都是简单属性,其赋值一定要放到双引号里 XAML解析器会根据属性的类型执行隐式转换 与C#的区别 SolidBrush.Color = Colors. ...