python版本 3.5

#Author by Liguangbo
#_*_ coding:utf-8 _*_
str="i like study python, welcome to my python program\t."
#首字母大写
print(str.capitalize())
#I like study python, welcome to my python program.
#关键字在字符串中出现的次数
print(str.count(" "))
#8
#打印100个字符,如果str不够,则用-代替,且字符str位于中间
print('hello world'.center(20,'-'))
#----hello world-----
#判断字符串是否以‘l’和‘.’开头结尾
print(str.startswith('l'))
#False
print(str.endswith('.'))
#True
#将tab键转为5个空格
print(str.expandtabs(tabsize=51))
#i like study python, welcome to my python program .
#查找第一个sub出现的位置
sub='p'
print(str[str.find(sub):])
#python, welcome to my python program .
#字符串的参数调用及赋值
s="my name is {name},i am {years} years old!"
print(s.format(name="ligb",years="28"))
print(s.format_map({'name': 'ligb' ,'years':28}))
#my name is ligb,i am 28 years old!
#判断是否是由阿拉伯数字或字母组成,不能包含符号、空格
x='我'
print(x.isalnum())
#True
#判断是否是纯字符,不能包含数字或者符号
print(x.isalpha())
#True
print('一'.isdecimal())
#False
print('1'.isdigit())
#True
#判断是否是小写、大写
print('a'.islower())
#True
print('a'.isupper())
#False
#判断是否所有单词首字母大写
print('My Name Is '.istitle())
#True
#判断文件是否可以打印
print('my name is ligb'.isprintable())#tty drive等文件不可打印
#True
#列表转字符串
print('%'.join(['wo','men','de','jia']))
#wo%men%de%jia
#若字符串长度不够20,则在末尾加*补充
print('hello world'.ljust(20,'*'))
#hello world*********
print('hello world'.rjust(20,'*'))
#*********hello world
#大小写转换
print('hello world'.lower())
print('hello world'.upper())
#hello world
#HELLO WORLD
#去掉首尾的回车或者换行
print(' hello world\n'.strip())
print('-----')
#hello world
#-----
#去掉左右的回车或者换行
print(' hello world\n'.rstrip())
print(' hello world\n'.lstrip()) #查找最右边的关键字
print('hello world !'.rfind('world'))
#以空格为分割符,生成列表
print(' '.join('hello world my name is'.split()))
print('hello world my name is'.split())
#['hello', 'world', 'my', 'name', 'is']
print('hello+world+my+name+is'.split('+'))
#['hello', 'world', 'my', 'name', 'is']
#按照换行来分
print('hello \n world'.splitlines())
#['hello ', ' world']
#调换大小写
print('Hello World'.swapcase())
#hELLO wORLD
print('hello world'.title())
#Hello World

python3 字符串相关函数的更多相关文章

  1. 009.Python字符串相关函数

    字符串相关函数 1 capitalize 字符串首字母大写 strvar = "this is a dog" res = strvar.capitalize() print(res ...

  2. python3字符串

    Python3 字符串 Python字符串运算符 + 字符串连接 a + b 输出结果: HelloPython * 重复输出字符串 a*2 输出结果:HelloHello [] 通过索引获取字符串中 ...

  3. Perl函数:字符串相关函数

    Perl字符串相关函数 字符串的内置函数有: chomp, chop, chr, crypt, fc, hex, index, lc, lcfirst, length, oct, ord, pack, ...

  4. [转]python3字符串与文本处理

    转自:python3字符串与文本处理 阅读目录 1.针对任意多的分隔符拆分字符串 2.在字符串的开头或结尾处做文本匹配 3.利用shell通配符做字符串匹配 4.文本模式的匹配和查找 5.查找和替换文 ...

  5. python3字符串操作

    python3字符串操作 x = 'abc' y = 'defgh' print(x + y) #x+y print(x * ) #x*n print(x[]) #x[i] print(y[:-]) ...

  6. db2字符串相关函数的使用

    db2字符串相关函数的使用 from :internet    一.字符转换函数 1.ASCII() 返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用‘’括起来 ...

  7. 【2】python3字符串的比较(辨析is与==的区别)

    PYTHON3基本数据类型(二.字符串) Python3字符串 ①字符串比较 1.比较字符串是否相同: ==:使用==来比较两个字符串内的value值是否相同 is:比较两个字符串的id值. 2.字符 ...

  8. python系列四:Python3字符串

    #!/usr/bin/python #Python3 字符串#可以截取字符串的一部分并与其他字段拼接var1 = 'Hello World!'print ("已更新字符串 : ", ...

  9. python3 字符串属性(一)

    python3 字符串属性 >>> a='hello world' >>> dir(a) ['__add__', '__class__', '__contains_ ...

随机推荐

  1. grabcut

    http://blog.csdn.net/zouxy09/article/details/8535087

  2. PythonDay02

    >三目运算符 简单的if---else---语句 result = 1234 if 1 > 2 else 4321 print(result) >集合 set集合,是一个无序且不重复 ...

  3. Cross-site Scripting (XSS) 阅读笔记

    本文源自 https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29 通过阅读和翻译,并按照自己的理解,整理成如下文档. 概述 XSS ...

  4. Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead

    Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead 在解决问题Underscores can only ...

  5. bzoj1741 [Usaco2005 nov]Asteroids 穿越小行星群

    网络流,对于每一个行星,将行星所在行到行星连一条流量为1的边,将行星到其所在列连一条流量为1的边,从源点到所有行连一条流量为1的边,将所有列到汇点都连一条流量为1的边,最大流即为答案. 代码 #inc ...

  6. nodejs框架express快速开始

    认识express 创建应用 get请求 简述中间件 all方法 use方法1 use方法2 回调函数 获取主机.路径名 Get请求 - query Get请求 - param Get请求 - par ...

  7. 十一、Java基础---------内部类与匿名内部类

    内部类分为普通内部类(有名)和匿名内部类.普通内部类分为成员内部类.局部内部类.静态内部类(嵌套内部类).顾名思义,内部类就是定义在一个类内部的类.什么时候都会使用内部类呢?当我们定义一个类,发现内部 ...

  8. dataURI V.S. CSS Sprites 移动端

    英文原文:http://www.mobify.com/blog/css-sprites-vs-data-uris-which-is-faster-on-mobile/ 中文翻译:http://www. ...

  9. SendMessage

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. Mac下安装LNMP(Nginx+PHP5.6)环境

    [转自:http://avnpc.com/pages/install-lnmp-on-osx] 安装Homebrew 最近工作环境切换到Mac,所以以OS X Yosemite(10.10.1)为例, ...