Python3 每次处理一个字符
"""
Python3.4【文本】之每次处理一个字符
"""
test_str = "my name is bixiaopeng" for x in range( 0, len(test_str)-1):
print ("## 通过索引遍历字符串: " + test_str[x]) for x in test_str:
print ("## 直接遍历字符串: " + x) thelist = list(test_str)
print (thelist) #['m', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'b', 'i', 'x', 'i', 'a', 'o', 'p', 'e', 'n', 'g'] for x in thelist:
print ("## 遍历list: " + x) def printstr(a):
print ("使用map遍历: " + a) list(map(printstr,test_str)) #注意: python3以后必须使用list来打印map的结果 [print ("## 列表推导遍历: " + i) for i in test_str ]
Python3 每次处理一个字符的更多相关文章
- for循环每次取出一个字符(不是字节)
python3.5 for循环每次取出一个字符(不是字节) #!/usr/bin/env python # -*- coding:utf-8 -*- my_str = "我是哈哈" ...
- 《Python CookBook2》 第一章 文本 - 每次处理一个字符 && 字符和字符值之间的转换
文本 - 总结: 什么是文本Python 中的string 类型是不可变类型.文本,一个字符的矩阵,每一个单独的文本快可以被缩进和组织起来. 基本的文本操作①解析数据并将数据放入程序内部的结构中:②将 ...
- python每次处理一个字符的三种方法
python每次处理一个字符的三种方法 a_string = "abccdea" print 'the first' for c in a_string: print ord(c) ...
- 玩转python之每次处理一个字符
在Python中字符就是长度为1的字符串,所以可以循环遍历一个字符串,依次访问每一个字符,得到你想要的处理前提: 一个列表是个好主意,就像这样:thelist = list(thestring) 当然 ...
- 字符串A转换到字符串B,只能一次一次转换,每次转换只能把字符串A中的一个字符全部转换成另一个字符,是否能够转换成功
public class DemoTest { public static void main(String[] args) { System.)); } /** * 有一个字符串A 有一个字符串B ...
- C++学习45 流成员函数put输出单个字符 cin输入流详解 get()函数读入一个字符
在程序中一般用cout和插入运算符“<<”实现输出,cout流在内存中有相应的缓冲区.有时用户还有特殊的输出要求,例如只输出一个字符.ostream类除了提供上面介绍过的用于格式控制的成员 ...
- 查找常用字符(给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。)
给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表. 例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 ...
- VIM 用正则表达式,非贪婪匹配,匹配竖杠,竖线, 匹配中文,中文正则,倒数第二列, 匹配任意一个字符 :
VIM 用正则表达式 批量替换文本,多行删除,复制,移动 在VIM中 用正则表达式 批量替换文本,多行删除,复制,移动 :n1,n2 m n3 移动n1-n2行(包括n1,n2)到n3行之下: ...
- php 去掉字符串的最后一个字符
原字符串1,2,3,4,5,6, 去掉最后一个字符",",最终结果为1,2,3,4,5,6 代码如下: $str = "1,2,3,4,5,6,"; $news ...
随机推荐
- BNUOJ 1260 Brackets Sequence
Brackets Sequence Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Origi ...
- SQL to MongoDB Mapping Chart
http://docs.mongodb.org/manual/reference/sql-comparison/ In addition to the charts that follow, you ...
- hdu 2647拓扑排序 容器
#include<stdio.h> #include<queue> #include<vector> #include<iostream> using ...
- System.out.print()思考?
System.out.print()思考 问题? System.out.pritln(); 中是包名.类名.方法名吗? 解释: Syste ...
- Ubuntu 16.04安装WPS
1.下载 http://community.wps.cn/download/ 根据需要对应版本进行下载deb包. 2.安装 sudo dpkg -i wps-office_10.1.0.5672~a2 ...
- Ubuntu 16.04安装uGet替代迅雷,并在Chrome中设置为默认下载器
uGet是采用aria2作为下载后端,所以两个软件都必须同时安装. 1.安装uGet sudo add-apt-repository ppa:plushuang-tw/uget-stable sudo ...
- Ubuntu 16.04添加阿里云源/163源
添加国内源有个好处,比如下载软件时直接时国内的服务器,速度有保证. 以下是操作方法: 1.备份 sudo cp /etc/apt/sources.list /etc/apt/sources.list. ...
- 1. CountDiv 数数有几个 Compute number of integers divisible by k in range [a..b].
package com.code; public class Test05_1 { public static int solution(int A, int B, int K) { // handl ...
- python基础学习之02 元组
#encoding=utf-8 # 元组与列表一样,也是一种序列 print (1,2,3) print 1,2,3 print(1,) print 1, a=1 print(type(a)) a=1 ...
- OCX 打包 CAB 与 JS 调用具体教程
近期在做一个 WEB 项目.须要调用 OCX 进行连接读卡器读卡.本来并不想用 OCX 技术.由于 ActiveX 技术是微软出品.这样就导致整个系统仅仅能使用 IE 浏览器(其它浏览器能够通 ...