• python 内置函数或函数(争取日更)


    Python rjust()方法


    描述

    Python rjust() 返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于字符串的长度则返回原字符串。

    语法

    rjust()方法语法:

    str.rjust(width[, fillchar]).rjust(width[, fillchar])

    参数

    • width -- 指定填充指定字符后中字符串的总长度.
    • fillchar -- 填充的字符,默认为空格。

    返回值

    返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于字符串的长度则返回原字符串

    实例

    以下实例展示了rjust()函数的使用方法:

    1. #!/usr/bin/python
    2. str = "this is string example....wow!!!";
    3. print str.rjust(50, '0');
    str = "this is string example....wow!!!"; print str.rjust(50, '0');

    以上实例输出结果如下:

    000000000000000000this is string example....wow!!! is string example....wow!!!

    python assert断言函数

    1. python assert断言是声明布尔值必须为真的判定,如果发生异常就说明表达式为假。
    2. 可以理解assert断言语句为raise-if-not,用来测试表示式,其返回值为假,就会触发异常。

    self.assertEqual(a,b,msg=msg)   #判断a与.b是否一致,msg类似备注,可以为空

    self.assertNotEqual(a,b,msg=msg)  #判断a与b是否不一致

    self.assertTrue(a,msg=none)    #判断a是否为True

    self.assertFalse(b,msg=none)   #判断b是否为false

    Python rstrip()方法

    正在上传…重新上传取消 Python 字符串


    描述

    Python rstrip() 删除 string 字符串末尾的指定字符(默认为空格).

    语法

    rstrip()方法语法:

    str.rstrip([chars]).rstrip([chars])

    参数

    • chars -- 指定删除的字符(默认为空格)

    返回值

    返回删除 string 字符串末尾的指定字符后生成的新字符串。

    实例

    以下实例展示了rstrip()函数的使用方法:

    1. #!/usr/bin/python
    2. str = " this is string example....wow!!! ";
    3. print str.rstrip();
    4. str = "88888888this is string example....wow!!!8888888";
    5. print str.rstrip('8');
    str = " this is string example....wow!!! "; print str.rstrip(); str = "88888888this is string example....wow!!!8888888"; print str.rstrip('8');

    以上实例输出结果如下:

    1. this is string example....wow!!!
    2. 88888888this is string example....wow!!!
    this is string example....wow!!! 88888888this is string example....wow!!!

    Python中的repr()函数

    Python 有办法将任意值转为字符串:将它传入repr() 或str() 函数。

        函数str() 用于将值转化为适于人阅读的形式,而repr() 转化为供解释器读取的形式。

      在python的官方API中这样解释repr()函数:

  • 相关阅读:
    mipi介绍
    压力测试的3种常见模式
    景联文科技:高质量数据采集清洗标注服务,助力大语言模型红蓝对抗更加精准高效
    Kafka 万亿级消息实践之资源组流量掉零故障排查分析
    close excel by keyword 根据关键字关闭 excel 窗口 xlwings 方式实现
    【MySQL】聊聊order by 是如何排序的
    三子棋小游戏思路及代码实现的详解
    windows 安装多个独立微信,设置不同快捷键
    Centos下安装MySQL,配置远程连接(无坑版)
    并查集及实现
  • 原文地址:https://blog.csdn.net/qq_37634812/article/details/79786488