[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 如果你需要使用计算机做很多工作,最终会发现很多任务需要自 ...
随机推荐
- Pop Easy – 轻松实现模态窗口的 jQuery 插件
PopEasy 是一款轻量的 jQuery 插件,可以帮助开发人员容易的创建效果精美的模态窗口.PopEasy 在主流浏览器中都能够正常工作,同时兼容 IE 7 哦. 您可能感兴趣的相关文章 Metr ...
- 【HTML5】浅析html使用SSE(Server-Sent Events)连接JSP
目录结构: // contents structure [-] 关于SSE的一些话 什么是SSE SSE的浏览器支持情况 SSE的工作机制 使用SSE连接JSP文件 HTMl页面 服务器端 错误 错误 ...
- ABAP 加密解密程序
用于对字符串的加密和解密: DATA: o_encryptor TYPE REF TO cl_hard_wired_encryptor, o_cx_encrypt_error TYPE REF TO ...
- ViewPager的使用小技巧
1.在ViewPager中默认加载当前屏幕上的界面和左右相邻界面的数据从而实现页面滑动的快速切换.可以通过调用setOffscreenPageLimit(int)方法,定制预加载相邻页面的数目. 2. ...
- Android Contextual Menus之一:floating context menu
Android Contextual Menus之一:floating context menu 上下文菜单 上下文相关的菜单(contextual menu)用来提供影响UI中特定item或者con ...
- UILabel用法
// UILabel -> UIView // UILabel用来显示文字内容 //创建一个Label,一般都直接通过initWithFrame确定位置跟大小 UILabel *lb = [[U ...
- 【代码笔记】iOS-禁止输入表情符号
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- IOS 音效
IOS 音效 音效我们也可以成为短音频通常在程序中播放时间为1~2秒. 在应用程序中起到点缀效果,提升整体用户体验 音效文件只需要加载一次 示例代码: // // ViewController.m / ...
- Web应用程序系统的多用户权限控制设计及实现-页面模块【9】
前五章均是从整体上讲述了Web应用程序的多用户权限控制实现流程,本章讲述Web权限管理系统的基本模块-页面模块.页面模块涉及到的数据表为页面表. 1.1页面域 为了更规范和方便后期系统的二次开发和维护 ...
- 如何退出调起多个Activity的Application?
1.记录打开的Activity 每打开一个activity,即记录下来,需要关闭时,关闭每一个activity即可. 2.发送特定的广播 在需要结束应用时,发送一个特定广播,每个activity收到此 ...