1. 序列:seq[n], seq[x:y], seq * n序列重复n次,切片, 序列翻转 s=”abcde", s[::-1]="edcba"

  内建函数:1. 类型转换: list(iter), str(obj), unicode(obj), tuple(iter) , 2. len(seq), max(), min() , reversed(), sorted(), sum(),

------------------------------------------------------------------------------------------------------------------------------

2. 字符串: in ,not in ,,, import string , string.uppercase="ABCD....XYZ",  string.digits = '0123456789'

3. string.upper(str), str1.join(str): 用str1将字符串str连接起来, eg:'-'.join('abc') = 'a-b-c'

4. 字符串格式化操作符%, %c, %r, %s, %d, %f , %%(输入百分号)

5. 字符串模板:substitute, safe_substitute(), 前者更为严谨

   from string import Template

  s = Template('There are $(howmany} ${lang} ccc)

  print s.substitute(lang="python", howmany=3)

6. 原始字符串操作符(r/R)

7. 内建函数, enumerate(), zip(): 返回一个字符串列表 s='123', t='abc', zip(s, t), [('1', 'a'), ('2', 'b'), ('3', 'c')]

  raw_input(),

  string.capitalize(),将字符串第一个字符大写

  string.count(str, beg=0,end=len(string))返回str在字符串中出现的次数

  string.decode(encoding="UTF-8" errors='strict') 解码

  string.encode(encoding="utf-8" errors='strict') 编码

  string.endswith(obj, beg=0, end=len(string)) 检查字符串是否以obj结束,返回True,或False

  string.expandtabs(tabsize=8) 把字符串中的ab符号转换为空格

  string.find(str, beg=0, end=len(string)), string.index(str, beg, end)跟find()方法一样,只不过如果str不爱string中会报异常

  string.isalnum(), string是字符或者数字

  string.isalpha() string都是字母

  string.isdecimal()

  string.isdigit()

  string.islower()

  string.isnumeric()

  string.isspace() , 只包含空格返回true

  string.join(seq) ,用string将seq分割开来

  string.ljust 左对齐

  string. lower()

  string.lstrip() ,截掉string左边的空格

  string.partition(str), 从str第一次出现的地方, 将string分割成三部分

  string.replace(str1, str2, num), 把string中的str1替换为str2, 如果num制定,则替换不超过num次

  string.rfind(str, beg, end) ,从右边查找,string.rindex() 从右边查找 string.rpartition(str),

  string.startswith(obj,beg, end)

  string.swapcase(),翻转string中的大小写

  string.upper()

  string.split(str, num) ,以str分割string,不超过num次  'abcbe'.split('b', 2) = ['a','c','e']

  -----------------------------------------------------------------------------------------------------------------------------------------

8. 列表

  1. list.append(str), del list[1], in , not in , 连接操作符“+”    list1 + list2。 重复操作符 *, list1 * 2 

  2. 内建函数 len(), max(), min(), sorted(), reversed(),  enumerate(), zip(), sum(), list(), tuple()

    list.append(obj), list.count(obj),计算obj出现的次数, list.extend(seq),把序列seq的内容添加到list中, list.insert(index, obj),                              list.pop(index=-1), 删除并返回制定位置的对象,默认是最后一个对象,list.remove(obj), 从列表中删除对象obj,list.reverse(),

    原地翻转,list.sort(func=None, key=None, reverse=False)

    sort() 无返回值,sorted(), reversed()有返回值。

  用列表模拟栈的操作:

  '''
Created on 2014-5-11
@author: jyp
'''
stack = []

def push():
    stack.append(raw_input("Enter new String: ").strip())
    
def pop():
    if len(stack) ==0:
        print "stack is null"
    else:
        print "Removed: [" ,`stack.pop()`, "]"
def veiwstack():
    print stack
CMDs = {'u': push, 'o': pop, 'v': veiwstack }

def showmenu():
    pr = """
    p(U)sh
    p(O)p
    (V)iew
    (Q)uit
    
    Enter your choice: """
    
    while True:
        while True:
            try:
                choice = raw_input(pr).strip()[0].lower()
            except (EOFError, KeyboardInterrupt, IndexError):
                choice = 'q'
            print '\n You picked: %s' % choice
            if choice not in 'uovq':
                print 'invalid option, try agagin'
            else:
                break
        if choice == 'q':
            break
        CMDs[choice]()
if __name__ == '__main__':
    showmenu()

模拟队列操作:只需将上述代码中def pop() 函数中的,`stack.pop()` 改为:`stack.pop(0)`
--------------------------------------------------------------------------------------------------------------------------------------------

9. 拷贝对象, 深拷贝,浅拷贝,    浅拷贝相当于将对象的引用赋值给另一个对象, 并未拷贝这个对象,只是拷贝了对象的引用。

  浅拷贝: 1. 使用切片操作进行浅拷贝, 2. 使用工厂方法。

        eg: person= ['name', ['savings', 100]]

           hubby = person[:]  #通过切片操作[:]

           wifey = list(person)    #通过工厂函数实现浅拷贝

      2. 深拷贝: import copy      wifey = copy.deepcopy(person);

  

  

  

day5_python学习笔记_chapter6_字符串列表元组的更多相关文章

  1. 1.C#基础学习笔记3---C#字符串(转义符和内存存储无关)

    技术qq交流群:JavaDream:251572072  教程下载,在线交流:创梦IT社区:www.credream.com ------------------------------------- ...

  2. Python第三天 序列 数据类型 数值 字符串 列表 元组 字典

    Python第三天 序列  数据类型  数值  字符串  列表  元组  字典 数据类型数值字符串列表元组字典 序列序列:字符串.列表.元组序列的两个主要特点是索引操作符和切片操作符- 索引操作符让我 ...

  3. Python第三天 序列 5种数据类型 数值 字符串 列表 元组 字典 各种数据类型的的xx重写xx表达式

    Python第三天 序列  5种数据类型  数值  字符串  列表  元组  字典 各种数据类型的的xx重写xx表达式 目录 Pycharm使用技巧(转载) Python第一天  安装  shell ...

  4. KVM虚拟化学习笔记系列文章列表(转)

    Kernel-based Virtual Machine KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之k ...

  5. 【学习笔记】字符串—马拉车(Manacher)

    [学习笔记]字符串-马拉车(Manacher) 一:[前言] 马拉车用于求解连续回文子串问题,效率极高. 其核心思想与 \(kmp\) 类似:继承. --引自 \(yyx\) 学姐 二:[算法原理] ...

  6. 「学习笔记」字符串基础:Hash,KMP与Trie

    「学习笔记」字符串基础:Hash,KMP与Trie 点击查看目录 目录 「学习笔记」字符串基础:Hash,KMP与Trie Hash 算法 代码 KMP 算法 前置知识:\(\text{Border} ...

  7. 《Python基础教程(第二版)》学习笔记 -> 第二章 列表和元组

    本章将引入一个新的概念:数据结构. 数据结构是通过某种方式阻止在一起的数据元素的集合,这些数据元素可以是数字或者字符,设置可以是其他数据结构. Python中,最基本的数据结构是序列(Sequence ...

  8. python学习笔记(一)---字符串与列表

    字符串的一些处理 字符串的大小写 name="lonmar hb" print(name.upper())#全大写 print(name.lower())#全小写 print(na ...

  9. Python学习笔记--Python字符串连接方法总结

    声明: 这些总结的学习笔记,一部分是自己在工作学习中总结,一部分是收集网络中的知识点总结而成的,但不到原文链接.如果有侵权,请知会,多谢. python中有很多字符串连接方式,总结一下: 1)最原始的 ...

随机推荐

  1. Attempt to call getDuration without a valid mediaplayer

    最近在做一个播放器的小例子,中途遇到 了这个错: Attempt to call getDuration without a valid mediaplayer 解决参考方案如下: 一是如果media ...

  2. oracle update语句的几点写法

    update两表关联的写法包括字查询 1.update t2 set parentid=(select ownerid from t1 where t1.id=t2.id); 2. update tb ...

  3. 查找EBS中各种文件版本(Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER)

    Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER (文档 ID 85895 ...

  4. JSON、XML 解析

    iOS开发--XML/JSON数据解析 不错的文章http://www.jianshu.com/p/a54d367adb2a

  5. 20151217--Ajax的一点补充

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. ES6笔记③

    1.查找关键字  includes(); 返回布尔值 //①:includes -->代替-->indexof-->返回布尔值 var str = "769909303&q ...

  7. 简单的BFS学习笔记

    什么是BFS传送门. 今天学习BFS,加油! 先定义个数组: struct Node{ int a=0; int b=0; int step=0; }; int map[5][4]={//地图 0,0 ...

  8. Linux学习之/etc/init.d/functions详解

    转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=28773997&id=3996557 /etc/init.d/f ...

  9. mysql自定义循环函数

    FUNCTION deyes.f_getSplitStringByIndex1_8(stringIn text, delimiter varchar(10), indexIn int) RETURNS ...

  10. CSS Hack代码与浏览兼容总结

    关于CSS Hack的东西能少尽量少吧.发现这篇文章我写得太复杂了,所以重新精简了一下,把代码粘贴到jsfiddle上,方面修改代码和维护. 1, IE条件注释法,微软官方推荐的hack方式. 只在I ...