center函数——str.center(width[, fillchar])

str.center(width[, fillchar])

自我理解

  • str是处理对象,类型为字符串。center是对字符串的填充处理函数。将字符串居中,两边填充指定字符fillchar(默认是空格)。返回的类型也是str字符串。
  • width:宽度,类型为整数int
  • fillchar:可选,填充字符,默认为空格
"Python".center(20, "*")

#*******Python*******

1、Dash中函数说明

  • Return centered in a string of length width. Padding is done using the specified fillchar (default is an ASCII space). The original string is returned if width is less than or equal to len(s).
  • 以指定长度width返回字符串。使用指定的fillchar进行填充(默认使用ASCII字符的空格键进行填充)。如果指定的width长度少于或等于字符串长度则返回原字符串。

2、标准库中的定义

    def center(self, *args, **kwargs): # real signature unknown
        """
        Return a centered string of length width.
        
        Padding is done using the specified fill character (default is a space).
        """
        pass
  • 返回一个指定宽度的居中字符串
  • 使用指定字符填充(默认使用空格)

3、pycharm注解

  • class str
    def center(self, width: int, fillchar: str = …)
    Inferred type: (self: str, width: int, fillchar: str) -> str
  • 类型:str
  • width类型:int,fillchar类型:str
  • 返回str类型
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值