zoukankan      html  css  js  c++  java
  • python开发[第二篇]------str的7个必须掌握的方法以及五个常用方法

    在Python中 基本数据类型有 str int boolean list dict tuple等 其中str的相关方法有30多个 但是常用的就以下7个

    join 
    # split
    # find
    # strip
    # upper
    # lower
    # replace

    除了以上7个常用方法外,还有个五基本方法务必牢记 在以后会经常用到

    一、for循环
    # for 变量名 in 字符串:
    # 变量名
    # break
    # continue


    # index = 0
    # while index < len(test):
    # v = test[index]
    # print(v)
    #
    # index += 1
    # print('=======')

    # for zjw in test:
    # print(zjw)

    # test = "让技术成为你的核心竞争力"
    # for item in test:
    # print(item)
    # break

    # for item in test:
    # continue
    # print(item)

    # 二、索引,下标,获取字符串中的某一个字符
    # v = test[3]
    # print(v)

    # 三、切片
    # v = test[0:-1] # 0=< <1
    # print(v)

    # 四、获取长度
    # Python3: len获取当前字符串中由几个字符组成
    # v = len(test)
    # print(v)

    # 五、获取连续或不连续的数字,
    # Python2中直接创建在内容中
    # python3中只有for循环时,才一个一个创建
    # r1 = range(10)
    # r2 = range(1,10)
    # r3 = range(1,10,2)
    # 帮助创建连续的数字,通过设置步长来指定不连续
    # v = range(0, 100, 5)
    #
    # for item in v:
    # print(item)

  • 相关阅读:
    js中删除数组元素的几种方法
    js中的prototype
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    angularjs事件传递$on、$emit和$broadcast
    cron表达式
    angularjs中的时间格式化过滤
    angularjs中的$q
    IOS 错误
    Swift 错误
    IOS 控件
  • 原文地址:https://www.cnblogs.com/lijun6/p/9307768.html
Copyright © 2011-2022 走看看