美文网首页
生信_Python 基础

生信_Python 基础

作者: 重拾生活信心 | 来源:发表于2023-10-17 10:50 被阅读0次

Python for Bioinformatics

Data types

数据类型

  • 整数(int)

  • 浮点数(float)

  • 复数(complex)

  • 字符串(str)

  • 布尔值(bool)

    • True
    • False
  • 空值 ( None )

容器类型

my_list = ['hello!', 'world']
my_tupple = ('hello!', 'world') 
my_dictionary= {'hi!' : 'hello!'  ,  '88' : 'Bye!' }
my_set = {'hello!', 'world'}

列表list [,]

  • 列表是有序的。
  • 列表里的元素,是可更改的。
  • 列表里的元素类型,不限于 数字,字符串,也可以是列表,元组,字典,集合.

元组tuple (,)

  • 元组是有序的。
  • 元组里的元素,设置后,就不能更改里面的元素了。

字典dict { : , : }

{ key :value }

  • key : 不可变objects,如 字符串、数字、元组。

集合set { , }

  • 可变
  • 元素无序、不重复(可用来去重)


    python data types

Operations for sequences

Strings

  • lower()
  • replace(old,new[,count])
  • count(sub[,start[,end]])
  • find(sub[,start[,end]]) : 有匹配则返回position,无则-1
  • index() :有匹配则返回position,无则 error
  • split(sep [,maxsplit])
  • join(seq)

List

Adding
  • append(element)
  • insert(position,element)
  • extend([list])
Removing
  • pop[index]
  • remove(element)
  • del list[index]
  • copy : b = a[:]
    list

Common Properties of Sequences [list \ tuple \ strings]

Indexing : []
  • 从0开始
  • 负数代表从右开始
seqdata = (’MRVLLVALALLA’, 12, ’5FE9EEE8EE2DC2C7’) 
seqdata[0][5]
 ’V’
Slicing : :
  • 切片(index for space)


    slicing index
    slice2
Membership Test : in
>>> point = (23, 56, 11)
>>> 11 in point True 
>>> my_sequence = ’MRVLLVALALLALAASATS’ 
>>> ’X’ in my_sequence 
False
Concatenation 连接
c()
len, max, and min
  • len() returns the length (the number of items) of a sequence
Turn a Sequence into a List

To convert a sequence (like a tuple or a string) into a list, use the list() method:

>>> tata_box = ’TATAAA’ 
>>> list(tata_box) [’T’, ’A’, ’T’, ’A’, ’A’, ’A’]
Dictionaries
dic dictionary_view
Set
  • inetrsection() : &
  • union() : |
  • difference() : -
  • symmetric_difference : ^
    SET.method()

Reference

相关文章

网友评论

      本文标题:生信_Python 基础

      本文链接:https://www.haomeiwen.com/subject/fpwfidtx.html