• 【字符串操作】


    #字符串操作
        #定义字符串
        a = "let's go"
        
        #字符串切片
        print("helloworld"[2:]) #通过索引获取字符串中的字符,和列表切片同理
        
        #关键字  in 
        print("llo" in "helloworld")  #返回TRUE或False
        
        #字符串拼接
        #可以用+拼接字符串
        #join实现拼接
            a = "123"
            b = "456"
            d = "789"
            c='***'.join([a,b,d]) #用*拼接a,b,c
            #返回123***456***789
        
        #%  格式化输出字符串
            print('there are some examples')
            print('%s are some examples' %'there')
        
        #字符串的内置方法
        st = "hello kitty{name}"
        st.count("t") #统计t的个数
        st.capitalize #首字母大写
        st.center(50."#") #居中
        st.endswith('ty') #以某个内容结尾
        st.startswith('he') #以某个内容开头
        st.expandtabs(tabsize = 20) #修改缩进
        st.find('t') #寻找,返回索引值
        st.format(name = "haha") #格式化输出的另一种方式
        print(st.index('t'))   #返回t的索引值
        print('My tLtle'.lower()) #将字符串里的字母全部转换为小写
        print('My tLtle'.upper()) #将字符串里的字母全部转换为大写
        print('	My tLtle
    '.strip()) #将字符串里不显示的内容去掉
        print('My title title'.replace('itle','lesson',1)) #替换,replace('被替换的值','替换后的内容',1(替换几个))
        print('My title title'.split('i',1)) #分割,split('分割值',分割次数)
    人生短短数十载,经不起几次重头再来
  • 相关阅读:
    ASP.NET MVC3 中设置htmlAttribute
    oracle查看表空间的几个sql
    SQL Server 中 sysobjects表
    Openal简介
    [转]DBUSGLIB Binding,GLIB事件与DBUS事件是如何关联的
    ffmpeg简介
    ffmpeg安装FAAC
    ffserver error
    Openal教程(二)
    centos下安装qt时出现/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found
  • 原文地址:https://www.cnblogs.com/bk770466199/p/5801630.html
Copyright © 2020-2023  润新知