zoukankan      html  css  js  c++  java
  • day06-string的内置方法

    st='hello kitty'
    print(st.count('l'))  #数字符串l的个数
    
    print(st.capitalize() ) #字符串首字母大写
    
    print(st.center(50,'-'))  #居中
    
    print(st.casefold())  #返回将字符串中所有大写字符转换为小写后生成的字符串。
    
    
    
    #print(st.encode())  #str.encode(encoding='UTF-8',errors='strict')
    
    print(st.endswith('y'))  #Python endswith() 方法用于判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False。
    # 可选参数"start"与"end"为检索字符串的开始与结束位置。
    
    print(st.startswith('he'))  #判断开头
    
    #st='he	llo kitty'
    #print(st.expandtabs(tabsize=10))   #扩展
    
    print(st.find('t'))  #空格也算位置,find查找第一个元素并将索引值返回,-1代表未找到
    
    st1='hello kitty {{}} {name} is {age}'
    print(st1.format(name='alex',age=36))  #格式化输出
    print(st1.format_map({'name':'alex','age':36}))  #格式化输出,但是要输入要是字典{}
    
    print(st.index('t'))   #空格也算位置,查找第一个元素并将索引值返回,未找到直接报错,不如find
    
    print('abc456$'.isalnum())  #是否含数字和字母,   否 则返回fasle
    print('0010'.isdecimal())   #判断是否是十进制
    print('23.11'.isdigit())    #是否整形
    print(''.isalpha()) 		#判断字母
    print('anc'.isidentifier())	#判断非法字符
    print('Abc'.islower())		#判断全小写
    print(''.upper())			#判断全大写
    print(''.isspace())			#判断是否空格
    print('My Title'.istitle())			#判断是否每个单词是否首字母大写
    
    print(st.lower())  #全部大写变小写
    print(st.swapcase()) #全部:大写变小写,小写变大写
    #print(''.ljust())    #和center类型,左对齐 print(st.rjust()),右对齐
    
    print('      my   title
             '.strip())   #用于移除字符串头尾指定的字符(默认为空格)或字符序列。换行符。
    print('ok is very good')
    print(st.lstrip())  #删左
    print(st.rstrip())	#删右
    
    print('	my title title
    '.replace('title','lesson',2))  #替换
    #''.replace('old','new',count次数)
    
    print('my title title'.rfind('t')) #返回字符串最后一次出现的位置,如果没有匹配项则返回-1。
    
    #分割 字符串
    print('my title title'.split(' '))	#通过''分割
    #拼接 字符串
    a='a'
    b='b'
    d='c'
    c= '-'.join([a,b,d])    #''对象 .join方法  ([])参数
    print(c)
    
    print(''.rsplit('i',))
    
    print(''.title())
    

      重要的:

    count

    center

    startswith()

    find

    format

    lower,upper:切片

    strip()

    replace()

    split()

  • 相关阅读:
    loadNibNamed 的使用
    重写UIPageControl实现自定义按钮(转)
    乔布斯办公室语录
    学ACM算法题有用吗?
    基于文法分析的表达式计算器的实现
    我的程序员之路(5)——工作一年
    XCode实用快捷键,谁用谁知道
    LR(1)语法分析表生成
    九大定律,四大原则
    汉字为何不能用笔画编码信息论系列
  • 原文地址:https://www.cnblogs.com/BBS2013/p/13093597.html
Copyright © 2011-2022 走看看