python字符串
来源:互联网 发布:通达信软件官网 编辑:程序博客网 时间:2024/06/14 16:42
关于python的split首先看以下程序:
s=input("s为:")#hello__our_world_print(s.split("_"))
输出为:[‘hello’, ”, ‘our’, ‘world’, ”],注意到输出为一个列表而非字符串,所以要想变为字符串首先要join一下,同时注意到s[1]是空而非our同时最后一个为空,但是如果是hello_our_world_此时s[1]便不再为空,值得思考,先记录一下。以下为写的几个复习字符串的小函数:
#对字符窜的小测试:删除"_"并且将非第一个"_"后字符大写#hello__our_world_s=input("s为:")def change(old,a): new=old.split(a) for i in range(len(new)): if i > 1 and new[i] !="" : new[i]=new[i][0].upper()+new[i][1:] return "".join(new)print(s.split("_"))print(change(s,"_"))
输入:hello__our_world_
输出:helloOurWorld
阅读全文
0 0
- Python字符串
- Python 字符串
- python字符串
- python 字符串
- 【python】-字符串
- python 字符串
- python字符串
- python 字符串
- python,字符串
- python 字符串
- Python字符串
- Python字符串
- python字符串
- Python 字符串
- python 字符串
- Python 字符串
- Python字符串
- python 字符串
- [ArcPy] ArcPy综合记录
- 数据库表及其字段变量命名神器之codeIf
- Leetcode之Reshape the Matrix 问题
- 问答机器人的Python分类
- FME常用函数
- python字符串
- hdu 2680
- SQL函数总结
- POJ 3384 Feng Shui (半平面交)
- Servlet 获取ServletContext对象
- sublime 常用功能
- jvm 垃圾回收
- 欢迎使用CSDN-markdown编辑器
- 习题8.4 畅通工程之最低成本建设问题(30 分)