python笔记之字符串
列表,元组,字符串的相互转换:
将字符串转换为序列和元组:
>>> s="hello"
>>> list(s)
['h', 'e', 'l', 'l', 'o']
>>> tuple(s)
('h', 'e', 'l', 'l', 'o')
>>> list(tuple(s))
['h', 'e', 'l', 'l', 'o']
>>> tuple(list(s))
('h', 'e', 'l', 'l', 'o')
将序列和元组转换为字符串:
>>> "".join(list(s))
'hello'
>>> "".join(tuple(s))
'hello'
>>> str(s)
'hello'
>>> str(list(s))
"['h', 'e', 'l', 'l', 'o']"
>>> str(tuple(s))
"('h', 'e', 'l', 'l', 'o')"
字符串方法:
(1)find:返回子字符串第一次出现最左端索引的位置
>>> s="hello"
>>> s.find("l")
2
(2)join
(3)lower:返回小写字母
python笔记之字符串的更多相关文章
- python笔记(2)--字符串
一.字符串 字符串是不可变序列,具有序列的公共操作方法,具体操作见python笔记(1)--序列(列表 元组 range) 1.创建字符串 单引号:'Hello , I am Logan ! ' 双引 ...
- python笔记3——字符串的操作
#Author:Wildwolf name="my name is wildwolf ," print(name.capitalize()) #首字母大写 print(name.c ...
- python3.4学习笔记(二十一) python实现指定字符串补全空格、前面填充0的方法
python3.4学习笔记(二十一) python实现指定字符串补全空格.前面填充0的方法 Python zfill()方法返回指定长度的字符串,原字符串右对齐,前面填充0.zfill()方法语法:s ...
- 【Python学习笔记】字符串操作
字符串的表示 python中的字符串是一个常量,可以使用单引号'',双引号""或三引号""" """来创建一个字符串常量 ...
- Python学习笔记整理(四)Python中的字符串..
字符串是一个有序的字符集合,用于存储和表现基于文本的信息. 常见的字符串常量和表达式 T1=‘’ 空字符串 T2="diege's" 双引号 T3=""&quo ...
- Python学习笔记(3)-字符串
创建字符串 一对单引号或双引号 >>> 'hello world' 'hello world' >>> "hello world" 'hello ...
- python笔记2-数据类型:字符串常用操作
这次主要介绍字符串常用操作方法及例子 1.python字符串 在python中声明一个字符串,通常有三种方法:在它的两边加上单引号.双引号或者三引号,如下: name = 'hello' name1 ...
- Python自学笔记之字符串的操作
1.将字符串全部变为小写:lower() casefold() 范围更广 2.将字符串全部变为大写:upper() 3.判断是否大小写:isupper() islower() 4.居中:center( ...
- Python笔记之不可不练
如果您已经有了一定的Python编程基础,那么本文就是为您的编程能力锦上添花,如果您刚刚开始对Python有一点点兴趣,不怕,Python的重点基础知识已经总结在博文<Python笔记之不可不知 ...
随机推荐
- HDU 1076 An Easy Task
题解:枚举即可…… #include <cstdio> int main(){ int now,y,n,T,count; scanf("%d",&T); whi ...
- Course(简单的字符串处理问题)
Course 时间限制:1000 ms | 内存限制:65535 KB [问题描述] There is such a policy in Sichuan University that if yo ...
- ubuntu 常用生产环境部署配置测试调优
1,ubuntu monogdb 安装配置 2,ubuntu jdk1.7,tomcat7安装 3,ubuntu LAMP部署 4,mongodb 远程热备份及恢复 使用自带的mongodump和mo ...
- Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9831 Accepted: 4779 De ...
- iOS开发笔记 基于wsdl2objc调用asp.net WebService
1.准备 先下载待会要用到的工具 WSDL2ObjC-0.6.zip WSDL2ObjC-0.7-pre1.zip 我用的是WSDL2ObjC-0.6.zip 1.1搭建asp.net WebServ ...
- POJ 1743 Musical Theme(不可重叠最长重复子串)
题目链接:http://poj.org/problem?id=1743 题意:有N(1 <= N <=20000)个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,现在要找一 ...
- BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富( dp )
dp , dp[ i ][ j ] = max( dp[ k ][ j - 1 ] ) + G[ i ][ j ] ( i - 1 <= k <= i + 1 , dp[ k ][ j - ...
- centos7安装mysql5.6
1.更新yum源 wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-communit ...
- this function has none of deterministic, no sql,or reads sql data in its declaration and binary logging is enabled
原址:http://blog.chinaunix.net/uid-20639775-id-3031821.html This function has none of DETERMINISTI ...
- php学习笔记(2)
1.算数运算 <?php $a = 8; $b = 2; $c = 3; echo $a+$b."<br>\n"; echo $a-$b."<br ...