some useful materials

Python完全新手教程

http://www.cnblogs.com/taowen/articles/11239.aspx (from taowen, BITer)

Note:

Part 1 Basic Data Structure

List, Dict(dictionary) and Turple are three main data structures in python, which are respond to set,mapping and ? in math.

List

my_list=[]
my_list=[1,2]
print my_list
my_list.append(3)
print my_list

list can be indexed: print my_list[1], which outputs 2

Dict

contact={}
contact["name"]="taowen"
contact["phone"]=68942443

Turple

my_turple = (1,2,3)
my_list = []
for i in my_turple:
my_list.append(i)
print my_list

Part 2 Basic Grammer

i = 5
n = 0
while i>0:
n = n + i
i = i - 1
print n while 1:
  inputed_num = input("input a number between 1 and 10\n")
  if inputed_num >= 10:
    pass
  elif inputed_num < 1:
    pass
  else:
    break
print "hehe, don't follow, won't out"

Part 3 IO

raw_input: return your inputs as a string.

input:convert your inputs to a digital number and return it.

COFFE BREAK

# import the module to create a GUI
fromt Tkinter import *
# create a main window
root = Tk()
# create a label which is located in the main window
w = Label(root, text="Hello, world!")
# put the label in main window in default way
w.pack()
# start a loop waiting for your input
root.mainloop()

Part 4 Exception Handling

try:
print input()
except:
print "there is an error in your input"

Part 5 Function

def square(x):
return x**2
print square(5) def swap(a,b):
# return a turple
  return (b,a)
print swap(1,2)

Whether the paramater in function can be modifed or not depends on the type of paramater. Data types such as number or string cannot be modified in funciton, while list could be modified when used as param. So it's better to think twice before sending the complex params to function(you may need to copy it in advance).

Part 6 File Operation in Python

#input
xxx = file('c:\\a.txt', 'r')
xxx_content = infile.read()
xxx_content = infile.readlines()
for xxx_line in xxx.readlines():
print "Line:", xxx_line
xxx.close() #output
xxx=file('c:\\test.txt','w')
xxx.write("billrice")
xxx.write("testtest")
xxx.write("enter\n")
xxx.writelines(['billrice','ricerice'])
xxx.close

Note that before running the xxx.close() sentence, there is just an empy test.txt file in C disk, xxx.close() completes the save operation.

COFFE BREAK : useful functions

eval(raw_input())
# input 1+2, output 3

Part 7 Class

class person:
   school = 'bit'
def _init_(self):
self.name = 'taowen'
self.id = 20022479
def say_id(self):
print "%s's id is %d" % (self.name, self.id) me = person()
me.say_id()

study notes for python的更多相关文章

  1. Machine Learning Algorithms Study Notes(2)--Supervised Learning

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  2. Machine Learning Algorithms Study Notes(3)--Learning Theory

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  3. Machine Learning Algorithms Study Notes(1)--Introduction

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1    Introduction    1 1.1    ...

  4. [Python Study Notes]匿名函数

    Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...

  5. [Python Study Notes]字符串处理技巧(持续更新)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  6. [Python Study Notes]with的使用

    在 Python 2.5 中, with 关键字被加入.它将常用的 try ... except ... finally ... 模式很方便的被复用.看一个最经典的例子: with open('fil ...

  7. [Python Study Notes]实现对键盘控制与监控

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  8. [Python Study Notes]实现对鼠标控制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  9. [Python Study Notes]批量将wold转换为pdf

    本文代码,由原ppt2pdf.py进行改写 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

随机推荐

  1. Redis 简单命令

    1. 新增 set keyName "keyValue" 2. 获取 get keyName 查看所有Key keys * 3. 删除 //删除当前数据库中的所有Key flush ...

  2. 安装完CentOS 7 后必做的七件事

    CentOS是最多人用来运行服务器的 Linux 版本,最新版本是 CentOS 7.当你兴趣勃勃地在一台主机或 VPS 上安装 CentOS 7 后,首要的工作肯定是加强它的安全性,以下列出的七件事 ...

  3. datetime

    DateTime字段类型对应的时间格式是 yyyy-MM-dd HH:mm:ss.fff ,3个f,精确到1毫秒(ms),示例 2014-12-03 17:06:15.433 . DateTime2字 ...

  4. [Linux编程]__read_mostly变量含义

    1.定义 __read_mostly原语将定义的变量为存放在.data.read_mostly段中,原型在include/asm/cache.h 中定义: #define __read_mostly ...

  5. 3、NASA NIST Big Data Architecture

    这篇关于大数据应用的讲解太好了,直接上图.Mattmann_S1P8_ESTF2015 来自为知笔记(Wiz)

  6. iOS屏幕适配

    ## iOS屏幕适配 ### iOS屏幕适配发展史 1> iPhone4以前(没有iPad) * 不需要屏幕适配 2> iPad.iPhone5等设备出现 * 需要做横竖屏适配 * aut ...

  7. ubuntu12.04下一个简单的conky安装

    这个conky用一些漂亮的圆圈来显示cpu,时钟,内存,交换空间,硬盘信息,网络及天气信息(不需要登陆任何网站噢).而且,提供多种色彩方案供选择,带发行版标记(fedora,mint,debian,o ...

  8. CSS 宝典

    input点击时候,有个灰块 outline:medium; -webkit-tap-highlight-color:rgba(0,0,0,0); -webkit-user-modify:read-w ...

  9. iOS10 权限适配

    权限适配 这应该算iOS10系统适配的范畴,最近这两个都在弄,所以就直接和Xcode8适配一起写出来了. 在iOS10之后需要在Info.plist中,添加新的字段获取权限,否则在iOS10上运行会导 ...

  10. Hibernate配置文档详解

    Hibernate配置文档有框架总部署文档hibernate.cfg.xml 和映射类的配置文档 ***.hbm.xml hibernate.cfg.xml(文件位置直接放在src源文件夹即可) (在 ...