zoukankan      html  css  js  c++  java
  • python学习笔记1(字符串操作)

    #字符串操作
    #example1  字符串截取
    strs = '123456789'
    
    print strs[0:1]  
    #1 输出0到1的字符
    
    print strs[1:6]
    #23456 输出1~6的字符串
    
    num = 18
    strs = '00000' + str(num) #合并字符串
    print strs[-5:]
    #00018 输出字符串右5位
    
    #example2 字符串替换
    str = 'akakak'
    str = str.replace('k',8) #将字符串里的卡全部替换成8
    print str
    #'a8a8a8'
    
    #example3 字符串查找
    str = 'a,hello'
    print str.find('hello') #查找hello
    #2
    
    #example4 字符串分割
    str = 'a,b,c,d'
    strlist = str.split(',') #用逗号分割字符串,并保存到列表
    for value in strlist:
    	print value
    
    #a b c d
    

      

  • 相关阅读:
    NC 5的开发环境起不了客户端
    NC 6系初始化EJB
    ubuntu安装javaweb
    html 优化
    ubuntu
    jquery
    前端优化
    京东设计中心
    html cookie
    html5 use video camera
  • 原文地址:https://www.cnblogs.com/longdidi/p/3157328.html
Copyright © 2011-2022 走看看