关于Python翻转诗句问题

img


急,明天考试,回头会统一采纳,谢谢
center30是为什么,这个是怎么翻转的,

center() 返回⼀个原字符串居中,并使⽤空格填充⾄长度 width 的新字符串。默认填充字符为空格
这段代码没有你说的翻转功能,只是把一行文字按照8个一组(一句)切割成4段,然后居中输出

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7480018
  • 这篇博客你也可以参考下:Python center 用法
  • 除此之外, 这篇博客: 来自python的【str字符串内置函数】中的 字符串内置函数–center 填充内容使得内容居中显示 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
    • str.center(width[,fillchar]) :定义一个width宽度的字符串,使数据居中显示,其余部分使用fillchar进行填充,如果未定义,默认为空格填充。

    • 参数至少为一个,最多为两个,str.center() 会报错 TypeError: center() takes at least 1 argument (0 given)

    • 会在width中居中显示,如果不是居中,那么前短后长哦~

    • fillchar 默认是空格,如果有参数,只能是一个字符,不然会报错The fill character must be exactly one character long

    • 如果width<str.len 会原样输出,并且也不会填充,也不会截取

    • help 输出的内容:

     center(...)
     |      S.center(width[, fillchar]) -> str  # 输出是一个字符串
     |      #s.center(宽度,填充字符) 填充字符是可选的吧
     |      Return S centered in a string of length width. Padding is
     |      done using the specified fill character (default is a space)
    
    # fillchar
    print('111111111111111111111111')#24
    print('hello'.center(24))
    print('hello'.center(3,'1')) # hello
    print('hello'.center(10,'-'))
    print('hello'.center(10,'*'))
    #print('hello'.center(10,'ss')) #The fill character must be exactly one character long
    
    
  • 您还可以看一下 青于蓝老师的Python企业招聘百万级信息爬取课程中的 爬虫项目需求以及实现思路讲解小节, 巩固相关知识点

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^