zoukankan      html  css  js  c++  java
  • 2. String

     1 #!/user/bin/env python
     2 # -*- coding:utf-8 -*-
     3 """
     4 string (scene):
     5     section : [start:end[:step]]
     6         containing "start" and does not contain "end"
     7         string = "1234567"
     8             1   2   3   4   5   6   7
     9             0   1   2   3   4   5   6
    10             -7  -6  -5  -4  -3  -2  -1
    11             string[:]           result : 1234567
    12             string[1:4]         result : 234
    13             string[-6:-3]       result : 234
    14             string[1:-3]        result : 234
    15             string[-6:4]        result : 234
    16             string[::3]         result : 147
    17             string[::-1]        result : 7654321
    18             string[-2::-2]      result : 642
    19             string[-3:-6:-1]    result : 543
    20             string[4:1:-1]      result : 543
    21             string[4:-6:-1]     result : 543
    22             string[-3:1:-1]     result : 543
    23         string.find() -> int        Return -1 on failure.
    24         string.index() -> int       Raises ValueError when the substring is not found.
    25         string.replace(old, new, count) -> string
    26             count :
    27                 Maximum number of occurrences to replace.
    28                 -1 (the default value) means replace all occurrences.
    29         string.split([sep], [maxSplit]) ->list
    30             sep
    31                 The delimiter according which to split the string.
    32                 None (the default value) means split according to any whitespace,
    33                 and discard empty strings from the result.
    34             maxSplit
    35                 Maximum number of splits to do.
    36                 -1 (the default value) means no limit.
    37         string.upper()
    38         string.lower()
    39         string.title()        words start with upper cased characters and all remaining cased characters have lower case.
    40         string.capitalize()   make the first character have upper case and the rest lower case.
    41 
    42         string.isupper()
    43         string.islower()
    44         string.isalpha()
    45         string.isdigit()
    46         string.startswith()
    47         string.endswith()
    48 
    49         string.center(width, [fillchar])
    50         string.ljust(width, [fillchar])
    51         string.rjust(width, [fillchar])
    52 
    53         string.format()
    54             name = "cxk"
    55             age = 18
    56             print("{}, age : {}, you are an idiot".format(name, age))
    57             print("{0}, age : {1}, you are an idiot".format(name, age))
    58             print("{}, age : {}, you are an idiot".format(name=name, age=age))
    59 
    60             money = 5.99458
    61             print("I have {:.2f}¥".formate(money))
    62 
    63         string.strip()
    64         string.rstrip()
    65         string.lstrip()
    66 
    67         stirng.join()
    68 
    69     String-Supported operators :
    70         + * in is == != [] % > <
    71 
    72 """
  • 相关阅读:
    兴趣遍地都是,专注和持之以恒才是真正稀缺的
    vuecli2和vuecli3项目中添加网页标题图标
    vue+sentry 前端异常日志监控
    从零构建vue项目(三)--vue常用插件
    从零构建vue项目(一)--搭建node环境,拉取项目模板
    dbvisualizer安装
    TS学习笔记----(一)基础类型
    基于weui loading插件封装
    UI组件--element-ui--全部引入和按需引入
    vue_全局注册过滤器
  • 原文地址:https://www.cnblogs.com/gebicungaha/p/11310483.html
Copyright © 2011-2022 走看看