python的字符串处理函数

字符串处理与特殊函数

用引号括起来的字符集合称之为字符串,,引号可以是一对单引号,双引号,三引号(单/双)

Notes:

  python中的三引号可以将复杂的字符串进行复制:python中的三引号允许一个字符串夸多行,字符串可以包含换行符,制表符,以及其他特殊字符,三引号的语法是一对连续的单引号或者双引号(通常都是成对的用)

In [70]: var1=‘you are a hero‘

In [71]: type(var1)
Out[71]: str

In [72]: var2="I am a girle"

In [73]: type(var2)
Out[73]: str

In [74]: var3=‘‘‘yes you are right‘‘‘

In [76]: type(var3)
Out[76]: str

In [77]: var4="""gagaga is lary gaga"""

In [78]: type(var4)
Out[78]: str

In [79]: 

In [79]: print("zhangsan is a ‘layde‘")
zhangsan is a ‘layde‘

In [80]: print(‘zhangsan is a "layde"‘)
zhangsan is a "layde"

  

原文地址:https://www.cnblogs.com/xindeng/p/8893054.html

时间: 2024-08-30 17:57:11

python的字符串处理函数的相关文章

Python的字符串方法/函数

S.find()#可指定范围查找字串,返回索引值,否则返回-1 S.index()#同find,只是找不到的之后返回异常 S.count()#返回找到字串的个数 S.lower()#转小写 S.capitalize()#首字母大写 S.upper()#转大写 S.swapcase()#大小写互换 S.split()#j将string转list,默认以空格切分 S.join()#将list转string 处理字符串的内置函数 len(str)    #返回字符串的长度 cmp(str,str)#字

Python:字符串处理函数

Split & Combine  #拆分和组合 #split() 通过指定分隔符对字符串进行切片 lan = "python ruby c c++ swift" lan.split() ['python', 'ruby', 'c', 'c++', 'swift'] todos = "download python, install, download ide, learn" todos.split(', ') ['download python', 'ins

python 用字符串调用函数名

方法暂时看到两种: ①eval: def a():     print '1' func_a = 'a' eval(func_a)() 结果:1 ②.vars: 获取当前环境中的全部变量. def a():     print '1' func_a = 'a' vars()[func_a]() 结果:1 对于多个函数统一管理的时候,上面两种写法比较方便,可以直接通过管理函数名变量,来直接控制函数的调用. 比如: def a():     print '1'      def b():     p

【Python】字符串处理函数

原文地址:https://www.cnblogs.com/HGNET/p/12114446.html

python字符串操作函数和string模块代码分析

原文链接:http://blog.chinaunix.net/uid-25992400-id-3283846.html python的字符串属性函数 字符串属性方法: >>> str='string learn' >>> dir(str) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute_

Python 的字符串类子串查找函数

Python 的字符串类有个很好用的函数,可很方便的用于与查找Python字符串类型对象子串相关的操作,具体的API如下: | find(...) | S.find(sub [,start [,end]]) -> int | | Return the lowest index in S where substring sub is found, | such that sub is contained within s[start:end]. Optional | arguments start

Python 的格式化字符串format函数

阅读mattkang在csdn中的博客<飘逸的python - 增强的格式化字符串format函数>所做笔记 自从python2.6开始,新增了一种格式化字符串的函数str.format(),他通过{}和:来代替%. 1.映射实例 In[1]: '{0},{1}'.format('abc', 18) Out[1]: 'abc,18' In[2]: '{}'.format(18) out[2]: 18 In[3]: '{1},{0},{1}'.format('abc', 123) out[3]:

Python内置的字符串处理函数整理

Python内置的字符串处理函数整理 作者: 字体:[增加 减小] 类型:转载 时间:2013-01-29我要评论 Python内置的字符串处理函数整理,收集常用的Python 内置的各种字符串处理 函数的使用方法 str='python String function' 生成字符串变量str='python String function' 字符串长度获取:len(str)例:print '%s length=%d' % (str,len(str)) 字母处理全部大写:str.upper()全

[摘抄]Python内置的字符串处理函数整理

str='python String function' 生成字符串变量str='python String function' 字符串长度获取:len(str)例:print '%s length=%d' % (str,len(str)) 字母处理全部大写:str.upper()全部小写:str.lower()大小写互换:str.swapcase()首字母大写,其余小写:str.capitalize()首字母大写:str.title()print '%s lower=%s' % (str,st