以Python 3.x版本为主
分隔字符串函数:partition,以某一字符进行分隔,分为三元元组,左中右
1、空格判断函数
编号 | 函数名 | 说明 |
1 | partition | 分隔字符,左边为分隔符字串,中间为分隔符本身,右边为分隔符字串 |
- 代码如下
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Apr 14, 2022 22:50 AM
str='Hello 51 CTO '
# 1、分隔函数 - partition
print('\n字符串%s,以空格进行分隔后的效果:%s' % (str,str.partition(" ")))
- 效果如下