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('分割值',分割次数)
    人生短短数十载,经不起几次重头再来
  • 相关阅读:
    触摸屏单点USB HID设置(老外写的 我看着基本没什么问题)
    USB 字段和包格式(1)
    LPC1343整理
    USB枚举和HID枚举实例(6)
    USB/HID设备报告描述符详解 (3)
    C# 值类型与引用类型(1)
    USB组合设备(5)
    千里之行,始于脚下
    c#中的结构体类型
    sqlmap 学习指南
  • 原文地址:https://www.cnblogs.com/bk770466199/p/5801630.html
Copyright © 2011-2022 走看看