• 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()函数:

  • 相关阅读:
    解决ConfigurationBuilder未包含“SetBasePath”的定义
    Java Spring框架 (底层原理+入门)
    华为数通方向HCIP-DataCom H12-831题库(单选题:301-310)
    matlab 采用描点法进行数据模拟和仿真
    数据分析---主要工作
    深入理解Kubernetes Pod调试
    按键中断小灯蜂鸣器风扇
    JavaAPI---replace
    Failed to connect to gitee.com port 443: Time out 连接超时提示【Bug已完美解决-鸿蒙开发】
    Git命令入门
  • 原文地址:https://blog.csdn.net/qq_37634812/article/details/79786488