Python笔记

来源:互联网 发布:新三板 软件 编辑:程序博客网 时间:2024/05/23 20:07

1,Python里的基础类型比如int, float,string的赋值都是内容拷贝的,而数据类型如列表,字典都是引用的:

a = 5

b = a

b = 3 //则a还是等于5,这是内容拷贝


a["a"]["b"] = 0

b = a["a"]

b["b"] = 4  //则a["a"]["b"] = 4,a的值也会变,这是引用


2,Python取时间

import datetime 
today = datetime.date.today() yesterday = today - datetime.timedelta(days=1)tomorrow = today - datetime.timedelta(days=1)print yesterday,today,tomorrrow
#2015-08-10

import time
print time.time()
输出的结果是:
1279578704.6725271(时间戳,不要小数的话强转int就行)

time.localtime()
(2015, 8, 19, 11, 33, 4, 2, 231, 0)


3,Python的文件读写

f = open('/yourpath', 'w') // r读 w写 W如果存在就覆盖 w+读写

line = f.readline()

if line == 0:

break:

or

while line in f:

都可以实现逐行读取


4,可以通过选中一大片区域然后按<或者>来集体缩进或者:6<来对第六行缩进






0 0