# value = "raitOrEi"
# v = value.capitalize()#首字母大写
# print(v)
# v1 = v.casefold()#全部变小写,不只是英文的,其他语言特殊的大小写也变换
# print(v1)
# v2 = v.lower()#只是英文变小写
# print(v2) # 设置宽度,并将内容居中
# 20 代指总长度
# 只能填充一个字符,字符可有可无,没有字符用空格填充
# value = "raitorei"
# v = value.center(20)
# print(v)
# v1 = value.center(20,"*")
# print(v1)
# v2 = value.ljust(20,"*")
# print(v2)
# v3 = value.rjust(20,"*")
# print(v3)
# v4 = value.zfill(20)#只能用0填充
# print(v4) # 去字符串中寻找,寻找子序列的出现次数
# value = "reraitorei"
# v1 = value.count('re')
# v2 = value.count('re',5)
# v3 = value.count('re',5,6)#起止位置
# print(v1)
# print(v2)
# print(v3) # encode
# decode # 以什么开始
# 以什么结尾
# test = "raitorei"
# v = test.startswith('r')
# print(v)
# v = test.endswith('i')
# print(v) #把字符串中的 tab 符号('\t')转为空格,tab 符号('\t')默认的空格数是 8.
#具体规则是,括号里是多少,以这个数字为一组,如果是开头,空格占位数字多少。比如
# test = "123\t456789"
# v = test.expandtabs()#123 456789 8个一组,空格补缺少的位置
# print(v)
# v1 = test.expandtabs(6)#123 456789 6个一组,空格补缺少的位置
# print(v1) # 从开始往后找,找到第一个之后,获取位置
# 大于等于开始,小于结束,未找到 -1
# test = "rei"
# v = test.find('r',0,2 )
# print(v) # index找不到,报错 忽略
# test = "rei"
# v = test.index('a')
# print(v) # 将一个字符串中的占位符替换为指定的值
# test = "I'm {name}, age {a}"
# print(test)
# v = test.format(name='raitorei',a=22)
# print(v) #将一个字符串中的占位符替换为指定的值,字典
# test = "I'm {name}, age {a}"
# print(test)
# v = test.format_map({"name": 'raitorei', "a": 22})
# print(v) # 星号 字符串中是否只包含字母,数字,汉字
# test = "fdfd1f风动旛动3"
# v = test.isalnum()
# print(v) # 星号 判断字符串中是否只包含字母,数字,汉字
# test = "fdfdf风动旛动"
# v = test.isalpha()
# print(v) # 判断字符串中是否是数字
# test = "123②"
# v = test.isdecimal()#②,特殊的不可以
# v1 = test.isdigit()#二,中文的数字不支持
# v2 = test.isnumeric()
# print(v,v1,v2) # 数字 字母 下划线 标识符:def class
# test = "a123"
# v = test.isidentifier()#数字开头false
# print(v) # 数字 字母 下划线 标识符:def class
# test = "a123"
# v = test.isidentifier()#数字开头false
# print(v) # 是否存在不能打印的字符,比如\t,结果是false
# test = "a\t123"
# v = test.isprintable()
# print(v) # 判断是否全部是空格
# test = " \t"
# v = test.isspace()
# print(v) # 判断是否是标题
# test = "the loneliest girl"
# v = test.istitle()
# print(v)
# v1 = test.title()
# print(v1)
# v2 = v1.istitle()
# print(v2) # ***** 加入字符
# test = "_"
# value = "raitorei"
# v = test.join(value)#等于"".join(value)
# print(v) # islower() 方法检测字符串是否由小写字母组成。
# isupper() 方法检测字符串中所有的字母是否都为大写。
# test1 = "abc"
# test2 = "abc123"
# test3 = "abc123A"
# v1 = test1.islower()
# v2 = test2.islower()
# v3 = test3.islower()
# print(v1,v2,v3)
# test4 = "ABC"
# test5 = "ABC123"
# test6 = "ABC123a"
# v4 = test4.isupper()
# v5 = test5.isupper()
# v6 = test6.isupper()
# print(v4,v5,v6) # 变换大小写
# test = "asdfgh"
# v = test.upper()
# print(v)
# v = v.lower()
# print(v) # 默认去除左右空格,\t,\n;可以指定字符
# test = " a s fgh "
# v = test.lstrip()
# print(v)
# v = test.rstrip()
# print(v)
# v = test.strip()
# print(v)
# v1 = v.strip("h")
# print(v1) # 变换大小写
# test = "asdfgh"
# v = test.maketrans("asd","123")
# print(v)
# v1 = test.translate(v)
# print(v1) # 分割字符,partition包含分隔符,split不包含分隔符
# test = "asdfghasdfghasdfgh"
# v1 = test.partition("f")
# print(v1)
# v2 = test.rpartition("f")
# print(v2)
# v3 = test.split("f",2)
# print(v3)
# v4 = test.rsplit("f",2)
# print(v4) # 分割换行符,默认不包含分隔符(false),true包含分隔符
# test = "asdfg\nhasd\nfghasdfgh"
# v1 = test.splitlines(True)
# print(v1) # 分割换行符,默认不包含分隔符(false),true包含分隔符
# test = "asdfg\nhasd\nfghasdfgh"
# v1 = test.splitlines(True)
# print(v1) # 大小写转换
# test = "asdfghJKL"
# v1 = test.swapcase()
# print(v1) #替换
test = "asdfghaJKaL"
# v1 = test.replace("a","b")
# print(v1)
# v2 = test.replace("a","b",2)
# print(v2)
################基本(7个)################
# join
# split
# find
# strip
# upper
# lower
# replace
################灰魔法(5个)################
test = "raitorei"
# #索引
# v1 = test[0]
# print(v1) # #切片
# v2 = test[0:-1]
# print(v2) # #长度
# v3 = len(test)
# print(v3)
# li = [1,2,3,4,5,"123"]
# print(len(li)) #循环输出
# index = 0
# while index < len(test) :
# print(test[index])
# index += 1
# print("---end---") # for demo in test:
# print(a) #帮助创建数字,可以设置隔多少再创建
# v = range(0,100,5)
# print(v)
# for vv in v:
# print(vv)
#将输入的文字的索引输出
value = input(">>>")
length = len(value)
num = range(0,length)
for f in num:
print(f,value[f]) # *****注意:
# 字符串一且自,不可修改。
# 一且修改或者拼接,部会造成重新生成字符串

  

python字符串(str)的更多相关文章

  1. Python字符串str的方法使用

    #!usr/bin/env python# -*-coding:utf-8-*-#字符串通常用双引号或单引号来表示:'123',"abc","字符串"#str字 ...

  2. Python 字符串 (str)

    作者博文地址:https://www.cnblogs.com/liu-shuai/ Python字符串的常用操作包括以下但不限于以下操作: 1 字符串的替换.删除.切片.复制.连接.比较.查找.分割等 ...

  3. python字符串str

    字符串str常用操作方法(都会产生新的数据) 1.取值: (1)索引:s[0] (2)切片:s[起始索引:结束索引:步长] 起始索引为0,可以省略 s最后一个索引可以取-1 结束索引省略,默认取到最后 ...

  4. python 字符串str和json格式转换

    最近在写一个脚本,需要处理从excel中读取的数据,发现读取的json格式数据进行转换时报错 ValueError: Expecting property name enclosed in doubl ...

  5. python字符串str和字节数组相互转化

    b = b"Hello, world!" # bytes object s = "Hello, world!" # str object print('str ...

  6. python字符串str和字节数组bytes相互转化

    1 引言 后续待补充 2 代码 b = b"Hello, world!" # bytes s = "Hello, world!" # string print( ...

  7. python字符串,常用编码

    Python的字符串和编码 1.常用编码 与python有关的编码主要有:ASCII.Unicode.UTF-8 其中ASCII如今可以视作UTF-8的子集 内存中统一使用Unicode编码(如记事本 ...

  8. python字符串/列表/元组/字典之间的相互转换(5)

    一.字符串str与列表list 1.字符串转列表 字符串转为列表list,可以使用str.split()方法,split方法是在字符串中对指定字符进行切片,并返回一个列表,示例代码如下: # !usr ...

  9. (原创)Python字符串系列(1)——str对象

    在本博客 <Python字符串系列> 中,将介绍以下内容: Python内置的str对象及操作 字符串的格式化 Python中的正则表达式 re模块 本文将介绍Python内置的 str ...

随机推荐

  1. 序列化方案选型对比 - JSON/ProtocolBuffer/FlatBuffer/DIMBIN

    4千字长文预警!! 背景 JSON/XML不好吗? 好,再没有一种序列化方案能像JSON和XML一样流行,自由.方便,拥有强大的表达力和跨平台能力.是通用数据传输格式的默认首选.不过随着数据量的增加和 ...

  2. ggplot2笔记

    ggplot2笔记 下面是ggplot2的一些文档和github上的源代码http://docs.ggplot2.org/current/https://github.com/hadley/ggplo ...

  3. oracle函数 mod(x,y)

    [功能]返回x除以y的余数 [参数]x,y,数字型表达式 [返回]数字 [示例] select mod(23,8),mod(24,8) from dual; 返回:7,0

  4. 是readdir,还是readdir_r

    readdir的原型如下: struct dirent *readdir(DIR *dirp); 因为内部使用了静态数据,所以readdir被认为不是线程安全的函数,POSIX[i]标准这样描述: T ...

  5. shell awk杂项

    awk '{ ;++i<=NF;){ a[i]=a[i]?a[i]",'\''"$i"'\''":"'\''"$i"'\'' ...

  6. @noi.ac - 491@ explore

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 最近有一个巨大的古代地下遗迹在比特镇被发现.这个地下遗迹的俯视图 ...

  7. php中 array_filter函数 的总结

    1.用此函数来过滤数组中的空元素 $arr1 = array('a'=>1,'b'=>0,'c'=>'','d'=>null,'e'=>5,'f'=>false); ...

  8. HTML静态网页--图片热点

  9. Python--day61 PyCharm连接MySQL工具的使用

    第一步:连接mysql数据工具的位置 第二步:选定数据库 第三步:下载驱动 第四步:连接数据库配置 第五步:在pycharm中查看数据库中的表 第六步:添加数据 第七步:打开用sql语句操作数据库的界 ...

  10. Delphi的不足

    Delphi拥有C#那样的开发速度,同时运行速度也很快,而且不需要.net运行时(可以免安装直接运行).为什么还是衰落了呢? 既不是单根体系,又缺少泛型支持.导致delphi没法做map.list.v ...