1.字符串string

推断一个字符(char)是数字还是字母

str.isalpha() #推断是否为字母
str.isdigit() #推断是否为数字

推断一个字符串是否为空

if not str.strip(): #推断是否为空,true表示空

向字符串加入内容

str = ''.join('love')

得到字符串固定长度的字串

>>>str = str1[1:3] #得到从下标1開始到下标3之前的字符,下标3的字符不算

字符串替换

>>>str.replace('abc','cde')

2.列表list

推断一个列表是否为空

>>>if len(lists):   #true表示空
#向列表中加入数据
>>>lists.append('1')
#得到list某个值的下标
>>>lists.index('1')

3.文件操作

读文件

>>>with open('filename','r') as f1:

写文件

>>>with open('filename','w') as f2:
>>> ......
>>> f2.write('my name is ldw.')

获得整个文件夹文件

>>>import os
>>>files = os.listdir("/ifs/home/liudiwei")
>>>for onefile in files: #onefile即递归得到的每一个文件
>>> ...

推断当前文件夹是否存在,不存在则创建文件夹:

if not os.path.exists(outdir): #假设outdir不存在,则创建该文件夹
os.makedirs(outdir)

python运行当前系统命令

os.system('[command]')  #command为想要运行的命令

4.集合操作

创建集合

s = set('thisisset')

加入元素

s.add('z')

集合长度

len(s)

推断集合非空

if len(s):   #假设长度为0,返回false

推断集合存在某元素

'k' in s    #或者能够是 'k' not in s

回收元素

del s

5.浮点数除法

设a和b为两整数。两数相除须要得到浮点结果

c=float(a)/float(b)

如须要保留小数

c=float('%.3f' % float(a)/float(b))

6.构建数组

生成一个8000*4的数组矩阵

def genMatrix():
AA=['A','C','D','E','F',
'G','H','I','K','L',
'M','N','P','Q','R',
'S','T','V','W','Y',]
triplet = []
for i in range(len(AA)):
for j in range(len(AA)):
for k in range(len(AA)):
triplet.append(AA[i]+AA[j]+AA[k]) rna=['A','U','G','C']
matrix = [[0 for col in range(len(rna))] for row in range(len(triplet))]
return triplet,rna,matrix'

7.字典

python字典比較有用,跟java/c++中的map相似。键值对。在实际其中,python能够依据键找到value。

定义

dict_map = {}
#赋值
dict_map['number'] = 2
#查看是否存在某个键
dict_map.has_key('number')#if exist, return True,else return False

Python学习笔记-小记的更多相关文章

  1. python学习笔记整理——字典

    python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...

  2. VS2013中Python学习笔记[Django Web的第一个网页]

    前言 前面我简单介绍了Python的Hello World.看到有人问我搞搞Python的Web,一时兴起,就来试试看. 第一篇 VS2013中Python学习笔记[环境搭建] 简单介绍Python环 ...

  3. python学习笔记之module && package

    个人总结: import module,module就是文件名,导入那个python文件 import package,package就是一个文件夹,导入的文件夹下有一个__init__.py的文件, ...

  4. python学习笔记(六)文件夹遍历,异常处理

    python学习笔记(六) 文件夹遍历 1.递归遍历 import os allfile = [] def dirList(path): filelist = os.listdir(path) for ...

  5. python学习笔记--Django入门四 管理站点--二

    接上一节  python学习笔记--Django入门四 管理站点 设置字段可选 编辑Book模块在email字段上加上blank=True,指定email字段为可选,代码如下: class Autho ...

  6. python学习笔记--Django入门0 安装dangjo

    经过这几天的折腾,经历了Django的各种报错,翻译的内容虽然不错,但是与实际的版本有差别,会出现各种奇葩的错误.现在终于找到了解决方法:查看英文原版内容:http://djangobook.com/ ...

  7. python学习笔记(一)元组,序列,字典

    python学习笔记(一)元组,序列,字典

  8. Pythoner | 你像从前一样的Python学习笔记

    Pythoner | 你像从前一样的Python学习笔记 Pythoner

  9. OpenCV之Python学习笔记

    OpenCV之Python学习笔记 直都在用Python+OpenCV做一些算法的原型.本来想留下发布一些文章的,可是整理一下就有点无奈了,都是写零散不成系统的小片段.现在看 到一本国外的新书< ...

随机推荐

  1. 网络 - 网关的作用、DNS的作用

    DNS的作用 域名系统.负责把域名翻译成ip,或者把ip翻译成域名. hosts文件用于静态的域名解析.优先级高于DNS解析. DNS服务器,负责解析域名到ip地址上. 114.114.114.114 ...

  2. 最全三大框架整合(使用映射)——applicationContext.xml里面的配置

    applicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <beans x ...

  3. 【BZOJ1010】【HNOI2008】玩具装箱toy (斜率优化DP) 解题报告

    题目: 题目在这里 思路与做法: 这题不难想. 首先我们先推出一个普通的dp方程: \(f_i = min \{ f_j+(i-j-1+sum_i-sum_j-L)^2\}\) 然后就推一推式子了: ...

  4. [codeforces contest 1119 F] Niyaz and Small Degrees 解题报告 (树形DP+堆)

    interlinkage: http://codeforces.com/contest/1119/problem/F description: 有一颗$n$个节点的树,每条边有一个边权 对于一个$x$ ...

  5. Cracking the Coding Interview 5.2

    Given a(decimal -e.g. 3.72)number that is passed in as a string, print the binary representation. If ...

  6. cloudfoundry service broker 制作

    实验室这边需要制作service broker.从今天开始将精力投入其中.

  7. linux编译安装gdb7.10.1

    1.下载GDB7.10.1安装包 #wget http://ftp.gnu.org/gnu/gdb/gdb-7.10.1.tar.gz 2.解压 #.tar.gz 3.创建安装目录 #/ #cd /u ...

  8. 2.TinkPHP入门----控制器

    1.控制器创建 命名规则:控制器名称+Controller+.class.php, 例如GoodsController.class.php  UserController.class.php 控制器结 ...

  9. Pinpoint 监控

    ####Hbase数据################ 参考: 然而没有卵用: https://blog.csdn.net/iamlihongwei/article/details/52882749? ...

  10. Tomcat web deploy

    环境: apache-tomcat-7.0.73 java version "1.8.0_112" 创建普通用户,使用 sudu进行操作 JDK 配置 下载地址:http://ww ...