zoukankan      html  css  js  c++  java
  • python

    # -*- coding:utf-8 -*-

    '''
    @project: jiaxy
    @author: Jimmy
    @file: study_3_str_内建函数.py
    @ide: PyCharm Community Edition
    @time: 2018-11-01 15:48
    @blog: https://www.cnblogs.com/gotesting/

    '''

    # 字符串的内建函数



    # 1. 查找某个字符
    # 字符串.find(指定的字符或者子字符串)
    # 若没有找到,则返回-1
    # 若找到,则返回索引

    s = '明天,你好!'
    print(s.find('@'))
    print(s.find('好'))
    print(s.find('你好'))


    # 2. 字符串的替换
    # 字符串.replace(目标,最终替换成什么)

    l = '举杯望明月'
    new_l = l.replace('望','看')
    print(new_l)


    # 3. 字符串的切割
    # 字符串.split()
    # 返回的数据类型 是 列表

    t = 'hi@Jimmy'
    t1 = t.split('@')
    print('切割后的结果值{}'.format(t1))


    # 4. 去除指定字符
    # 字符串.strip()
    # 去掉头和尾 指定的字符

    m = 'I love Python 6 ! 666'
    m1 = m.strip('6')
    print('去掉6后的结果值{}'.format(m1))


    # 5.变换大小写
    # 字符串.upper() 变成大写
    # 字符串.lower() 变成小写
    a = 'hello'
    b = 'WORLD'
    c = 'IloveYOU'
    a1 = a.upper()
    b1 = b.lower()
    c1 = c.upper()
    c2 = c.lower()
    print(a1,b1,c1,c2)


    # 6.首字母大写
    # 字符串.capitalize()
    print(c.capitalize())

    # 7. 统计字符串中字符的个数
    # 字符串.count(指定字符)
    print(c.count('o'))

    # 8. 居中
    # 字符串.center()

    # 9. 返回字符所在索引
    # 字符串.index(指定字符)
    print(c.index('o'))

    
    
  • 相关阅读:
    [bzoj4364] [IOI2014]wall砖墙
    [bzoj3064] [Tyvj 1518] CPU监控
    [bzoj3434] [WC2014]时空穿梭
    ASP.NET
    ASP.NET
    ASP.NET
    ASP.NET
    ASP.NET
    ASP.NET
    MSSQL
  • 原文地址:https://www.cnblogs.com/gotesting/p/9890150.html
Copyright © 2011-2022 走看看