str. list. dict. tuple.的使用

1.判断一个字符是否在str中,判断一个对象是否在list中,判断一个键是否在一个字典中,判断一个对象是否在一个tuple中,均可使用in,相反可以使用not in

2.str中的format可以使 { } 中的替换成传入的参数

  e.  test = 'i am {name}, {age}'

    test = test.format(name='fyh', age=19)

  对于上式,也可以使用一个字典进行传入,但要进行 ** 的处理

      test = test.format(**{'name': 'fyh', 'age' : 19})

  或者直接可以用format_map传入字典类型即可

     test = test.format_map({'name': 'fyh', 'age' : 19})

3.expandtabs 可以将str中每个 \t 之前的内容分成固定长度

    # test = "username\temail\tpassword\ndjkafsda\[email protected]\t123\ndjkafsda\[email protected]\t123\ndjkafsda\[email protected]\t123\n"
    # v = test.expandtabs(30)
    # print(v)

4.

猜你喜欢

转载自www.cnblogs.com/MarkFo/p/10042299.html
今日推荐