python中raw_input().strip().split()
来源:互联网 发布:外汇mt4软件下载 编辑:程序博客网 时间:2024/06/07 03:46
1、strip()方法
strip() 方法用于移除字符串头尾指定的字符(默认为空格)。
strip()方法语法:
str.strip([chars])
参数是chars--移除字符串头尾指定的字符.
例子如下:
#!/usr/bin/pythonstr = "HHHH I am a student HHHHH";print str.strip( 'H' );
输出:I am a student
2、split()方法
split()方法通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串
split()方法语法:
str.split(str="", num=string.count(str)).
参数:
- str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
- num -- 分割次数。
例子如下:
#!/usr/bin/pythonstr = "Line1-abcdef \nLine2-abc \nLine4-abcd";print str.split( );print str.split(' ', 1 );
输出:
['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
['Line1-abcdef', '\nLine2-abc \nLine4-abcd']
3、下面举出一个综合例子说明一下:
raw_input().strip().split()效果
raw_input() #' insert 0 5 'raw_input().strip() #'insert 0 5'raw_input().strip().strip() #['insert', '0', '5']
左边是输入,右边为输出结果
参考:http://www.runoob.com/python/att-string-split.html
http://stackoverflow.com/questions/40598078/how-does-raw-input-strip-split-in-python-work-in-this-code
0 0
- python中raw_input().strip().split()
- python中strip和split的使用
- python中strip() 函数和 split() 函数
- Python中strip和split的使用
- python中split()函数与strip()
- python strip() split()函数
- python strip() split()函数
- python strip() split()函数
- python strip() split()
- python ''.join,split(),strip()
- Python: strip() & split()
- python中strip() 函数和 split() 函数的理解
- Python中strip() 函数和 split() 函数的理解
- python中strip() 函数和 split() 函数的理解
- 【Python】 strip(),split()函数介绍
- python 中的split()和strip()
- python中的strip和split
- Python strip() 和split() 函数
- linux CentOS7 更改主机名
- VIN识别码OCR识别技术如何
- part-6 电源抑制比AC-PSRR
- 专访许鹏:谈C程序员修养及大型项目源码阅读与学习
- Java -- CheckStyle 常见错误列表
- python中raw_input().strip().split()
- 二叉树的最大节点
- python初步学习知识点1
- mysql删除匿名用户
- Cookie的setPath(),和setDomain()方法
- 常见自动机综述
- part-7 共模抑制比CMRR
- Problem Preparation
- part-8 共模抑制比CMRR的影响