zoukankan      html  css  js  c++  java
  • Python--字符串操作

    # #-*- coding: utf-8 -*-
    '''
    Created on 2017年12月31日
    
    @author: soyo
    '''
    str="i learn python and learn Spark"
    print str , str[0],str[-1] 
    print str[:6]     #切片操作
    str2="i like 'Spark' "
    print str2
    # ""的作用:取消自动换行
    str3="""Python 具有丰富的库,       
    使用用途很广。常见的就是对
    机器学习的使用。
    但是,'Spark' 也很强哦 """ 
    print str3  
    #特殊字符处理
    print "E:
    otePython.doc"      #
     变为换行符
    print r"E:
    otePython.doc"     # +r 处理
    print '-'*50
    print "字符串格式化输出"
    format_str5="There are {0} apples {1} the windows".format(2, "on")
    print format_str5
    print '-'*50
    print "字符串方法使用"
    print "***************"
    str5="5789610"
    print "将字符串以指定分隔符连接生成一个新的字符串"
    print ">".join(str5)   
    print "字符串全部变为大写"      
    print str.upper()
    print "统计字符串中’learn’的个数"
    print str.count("learn")
    print str.replace("learn", "learn_soyo")

    结果:

      i learn python and learn Spark i k
    i lear
    i like 'Spark'
    Python 具有丰富的库,       
    使用用途很广。常见的就是对
    机器学习的使用。但是,'Spark' 也很强哦
    E:
    otePython.doc
    E: otePython.doc
    --------------------------------------------------
    字符串格式化输出
    There are 2 apples on the windows
    --------------------------------------------------
    字符串方法使用
    ***************
    将字符串以指定分隔符连接生成一个新的字符串
    5>7>8>9>6>1>0
    字符串全部变为大写
    I LEARN PYTHON AND LEARN SPARK
    统计字符串中’learn’的个数
    2
    i learn_soyo python and learn_soyo Spark

  • 相关阅读:
    vue3_10 吴小明
    ios圆角属性失效的解决办法 吴小明
    vue3_07 吴小明
    vue3_04 吴小明
    vue3_08 吴小明
    vue3_09 吴小明
    vue指定返回键的路由(点击浏览器的返回按钮/beforeRouterLeave) 吴小明
    Object.assign() 吴小明
    vue中使用lodash的debounce(防抖函数) 吴小明
    读雪中悍刀行有感
  • 原文地址:https://www.cnblogs.com/soyo/p/8157574.html
Copyright © 2011-2022 走看看