• python 字符串相关知识


    1. float转String
    a = 1.2553435435435 # f前面的数字表示,保留的小数位数 bb = "%.0f" % a print(bb)

     2. Python 字符串中,个单词反转,保留空格

    1 import re
    2 str_a = "I love this Game"
    3 str_split = re.split('(s+)', str_a)
    4 str_split.reverse()
    5 print("".join(str_split)) #将数组转成字符串

    输入结果:  Game this love I

    3. 关于切片的语法:

    [起始:结束:步长], 也可以简化为[起始:结束]

    list_arr[0:3], 索引从0开始取,直到索引3结束,且不包括索引3.即: 0,1,2

  • 相关阅读:
    多行文字垂直居中效果(利用flex)
    Switch
    Scanner
    Method
    Recursion递归
    for
    if
    dowhile
    while
    DataType 数据类型
  • 原文地址:https://www.cnblogs.com/irisWhq/p/11572561.html
Copyright © 2020-2023  润新知