一.字符串的定义

Python——字符串使用

二.字符串的特性
1.索引

索引: 0,1,2,3,4 索引值默认从0开始

Python——字符串使用

2.切片
切片的规则: s[start????step] 从start开始,到end-1结束,步长:step

Python——字符串使用
Python——字符串使用

3.显示所有字符

Python——字符串使用

Python——字符串使用

4.显示前三个字符

Python——字符串使用

5.字符串逆序输出

Python——字符串使用

6.除了第一个字符外,其它全部输出

Python——字符串使用

7.重复

Python——字符串使用

8.连接

Python——字符串使用

9.成员操作符

Python——字符串使用
Python——字符串使用

三.回文数判断

Python——字符串使用

四.字符串判断
判断字符串里面每个元素是否为某种类型

print('123'.isdigit())
print('123abc'.isdigit())   ##判断是否为数字

title:首字母大写,其余字母小写
print('Hello'.istitle())
print('HeLlo'.istitle())   ##判断是否为标题

print('hello'.upper())
print('hello'.isupper())
print('hElLo'.lower())
print('hElLo'.islower())   ##判断是否为大小写

print('123'.isalnum())   ##判断是否为数字

print('123'.isalpha())
print('abc'.isalpha())     ##判断是否为字母

print(isinstance(1,int))    ##判断1是否为整数,是的话显示True,不是的话显示Faulse
print(isinstance('a',str))
print(isinstance(1,str))

五.字符串去掉开头和结尾
自动补齐字符串前后空格

Python——字符串使用

自动补齐左边空格

Python——字符串使用

自动补齐右边空格

Python——字符串使用

忽略换行及转换符号的自动补齐格式

Python——字符串使用

Python——字符串使用

删除字符串的字符

Python——字符串使用

六.字符串的搜索和替换
find找到子串,并返回最小的索引

Python——字符串使用

rfind找到子串,并返回最大的索引值

Python——字符串使用

换字符串中所有的‘hello’为‘westos’

Python——字符串使用

七.字符串的对齐

Python——字符串使用

八.字符串统计

Python——字符串使用

九.字符串的分离和连接

Python——字符串使用

Python——字符串使用

相关文章:

  • 2021-11-10
  • 2021-09-10
  • 2021-11-27
  • 2021-09-09
猜你喜欢
  • 2021-12-29
  • 2021-05-02
  • 2021-09-14
  • 2021-09-29
  • 2021-04-18
  • 2021-08-28
相关资源
相似解决方案