zoukankan      html  css  js  c++  java
  • count()函数与center()函数

    count()函数
    描述:用于统计字符串李某个字符出现的次数。可选参数为在字符串搜索的开始和结束位置
    语法:str.count(sub,start=0,end=len(string))
    返回值:子字符串在字符串中出现的次数

    str='www.runoob.com'
    sub='o'
    print('str.count('o'):',str.count('sub'))

    count()函数描述:用于统计字符串李某个字符出现的次数。可选参数为在字符串搜索的开始和结束位置语法:str.count(sub,start=0,end=len(string))返回值:子字符串在字符串中出现的次数

    str="www.runoob.com"
    sub='o'
    print ("str.count('o') : ", str.count(sub))
    
    sub='run'
    print ("str.count('run', 0, 10) : ", str.count(sub,0,10))

    center()函数

    描述:center()方法返回一个指定宽度width居中的字符串,fillchar为填充的字符。默认为空格

    语法:str.center(width[,fillchar])
    返回值:返回一个指定的宽度 width 居中的字符串,如果 width 小于字符串宽度直接返回字符串,否则使用 fillchar 去填充。

    >>> str = "[www.runoob.com]"
    >>> print ("str.center(40, '?!') : ", str.center(40, '?!'))
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: The fill character must be exactly one character long
  • 相关阅读:
    bzoj1084
    bzoj1088 [SCOI2005]扫雷
    [LUOGU] 1892 团伙
    [普及组] 2017 成绩
    [LUOGU] P2661 信息传递
    [LUOGU] P1339 [USACO09OCT]热浪Heat Wave
    [LUOGU] P1828 香甜的黄油 Sweet Butter
    [模板] 单源最短路径
    [LUOGU] 1717 钓鱼
    [UVA] 704 Colour Hash
  • 原文地址:https://www.cnblogs.com/bashliuhe/p/13178170.html
Copyright © 2011-2022 走看看