zoukankan      html  css  js  c++  java
  • 【字符串操作】

    #字符串操作
        #定义字符串
        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('分割值',分割次数)
    人生短短数十载,经不起几次重头再来
  • 相关阅读:
    html5语法
    Addthis使用
    css font-weight原理
    css3 background
    jquery对标签属性操作
    给textarea添加背景图
    label的for属性
    css3 text-shadow
    z-index堆叠规则
    css3 @font-face
  • 原文地址:https://www.cnblogs.com/bk770466199/p/5801630.html
Copyright © 2011-2022 走看看