Python字符串在实际中的操作手册

开发 后端
Python字符串如何进行相关环境的融合与使用。这个问题需要大家进行学习相关的知识。下面我们就详细的看看相关的技术问题。

Python字符串在使用的时候是需要我们进行详细的学习。下面我们就看看在具体的操作中如何才能更好的进行这个字符串的使用方法。在之后的使用中还是需要我们继续学习。

#coding:utf-8   
#两个小函数  
#一、查找字符在字符串中第一次出现的位置.   
def find(string, char):   
index = 0   
while index < len(string):   
if (string[index] == char):   
return index   
index += 11  
return -111   
#二、查找字符在字符串中的总数  
def findSum(string, char):  
index = 0 
count = 0 
while index < len(string):  
if (string[index] == char):  
count += 1  
index += 1  
return count  
#使用以上两个函数  
print "字符1在字符串1211211234中第一次出现的位置: ", find("1211
211234", "1")  
print "字符1在字符串1211211234中出现的次数:", findSum("1211211
234", "1")  
import string #引入string库   print string.find('www.cctv.com', 'com') #result=9   print string.find('Good','d') #result = 3  print string.find('canada', 'a',2,9) #result =3,用法如下:   #string.find(s, sub[, start[, end]])函数说明   #Return the lowest index in s where the substring sub is 
found such that sub is  
#wholly contained in s[start:end]. Return -1 on failure. 
Defaults for start and  
#end and interpretation of negative values is the same 
as for slices.  
print string.lowercase #常量,abcdefghijklmnopqrstuvwxyz   print string.uppercase #常量,ABCDEFGHIJKLMNOPQRSTUVWXYZ   print string.digits #常量,012345678937    def isLower(char): #判断一个字符是否为小写   if (string.find(string.lowercase, char) > -1):   return 'Good'   return 'bad'   print isLower('S')   def isLowertest(char): #另外一种判断字符是否为小写的方法   return char in string.lowercase46 print isLowertest('a')  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.

以上就是对Python字符串的相关介绍,希望大家有所收获。

【编辑推荐】

  1. 探究Python性能为什么如此的强大
  2. Python编程语言在未来的发展趋势
  3. Python多线程具体运用的方法
  4. Python编程语言的发展历程介绍
  5. Python编程语言与Zpoe之间不解的情缘
责任编辑:张浩 来源: 博客园
相关推荐

2010-03-18 17:23:55

Java Socket

2010-03-11 18:21:43

Stackless P

2009-12-01 14:43:28

安装RDAC驱动

2009-12-22 17:24:14

Linux配置Dual

2010-03-16 10:58:35

Python字符串

2009-12-23 16:29:01

Linux操作系统

2009-12-17 16:10:24

Linux系统安装声卡

2009-12-02 15:57:26

Linux系统

2010-03-16 16:22:36

Python字符串

2010-06-01 17:45:45

SVN 基本操作

2010-06-17 16:22:04

SQL Server

2010-03-22 18:53:53

Python格式化字符

2010-03-22 18:20:47

Python正则表达式

2010-06-07 16:36:29

MySQL连接字符串

2010-04-15 16:47:46

Oracle字段

2020-09-24 10:45:52

计算机互联网 技术

2023-09-26 19:45:47

2010-06-17 16:38:14

MS SQL Serv

2010-09-06 17:30:46

SQL函数

2021-09-10 08:18:31

Go语言字符串
点赞
收藏

51CTO技术栈公众号