美文网首页
【18】python第十八--字符串的修改、对齐

【18】python第十八--字符串的修改、对齐

作者: 咗嚛 | 来源:发表于2020-03-21 22:17 被阅读0次

mystr = 'hello world and itcast and itehima and Python'

1.capitalize() 字符串首字母大写 Hello world and itcast and itehima and python

new_str = mystr.capitalize()
print(new_str)

2.title(): 字符串每个单词首字母大写 Hello World And Itcast And Itehima And Python

new_str1 = mystr.title()
print(new_str1)

3.upper() : 小写转成大写 # HELLO WORLD AND ITCAST AND ITEHIMA AND PYTHON

new_str2 = mystr.upper()
print(new_str2)

4. lover() 大写转小写 hello world and itcast and itehima and python

new_str3 = mystr.lower()
print(new_str3)

删除空格 空白

  1. lstrip() 删除字符串左侧空白字符(l --left )
  2. rstrip() 删除字符串右侧的空白字符 (r --right)
  3. strip() 删除字符串两侧空白字符

字符串对齐操作--

  1. ljust() 让字符串左对齐
  2. rjust() 字符串右对齐
  3. center() 中间对齐(如果是奇数,左侧会少一个字符

字符串序列.ljust(长度,填充字符)
mystr = 'hello world'
mystr.ljust(20,'.')
hello world......
----若字符串长度不够的时候,用''内的内容填充

相关文章

  • 【18】python第十八--字符串的修改、对齐

    mystr = 'hello world and itcast and itehima and Python' 1...

  • python中format函数

    python中format函数用于字符串的格式化 通过关键字 通过位置 填充和对齐^<>分别表示居中、左对齐、右对...

  • 字符串

    Python中的字符串 在Python中字符串是以单引号或双引号引起来的。 字符串不能直接修改,例如str[...

  • python数据类型

    字符串 类型:python中的数据类型 特性:不能修改 格式: 字符串的用法: 列表 类型:python中的数据类...

  • 【Python进阶】2.13 字符串对齐

    2.13 字符串对齐 问题 你想通过某种对齐方式来格式化字符串 解决方案 对于基本的字符串对齐操作,可以使用字符串...

  • python字符串

    字符串一旦创建,不可修改 一旦修改或者拼接,都会造成重新生成字符串 #! /usr/bin/env python ...

  • 自学Python:Python ljust()方法

    Python ljust() 方法返回一个原字符串左对齐,并使用空格填充至指定长度的新字符串。如果指定的长度小于原...

  • 2018-06-30 python 格式化输出%s

    Python格式化输出%s和%d python %s深入解析 %-*s 代表输入一个字符串,-号代表左对齐、后补空...

  • python中进行字符串排序

    python中进行字符串排序 python中没有直接的方法对字符串进行排序,原因是字符串类型是不允许直接修改元素的...

  • 2018-02-21-Python下单格式化输出

    前言 用python上某浴谷oj刷题,然后在格式化输出炸了 字符串拼接大法不能设置左对齐右对齐和小数后补齐,然后思...

网友评论

      本文标题:【18】python第十八--字符串的修改、对齐

      本文链接:https://www.haomeiwen.com/subject/kmusdhtx.html