1、S.isdecimal() -> bool
    Return True if there are only decimal characters in S, False otherwise. 字符串如果是十进制,返回True。

2、S.isdigit() -> bool
     Return True if all characters in S are digits and there is at least one character in S, False otherwise.
3、S.isnumeric() -> bool
    Return True if there are only numeric characters in S,
    False otherwise.

数字

 >>> num=''
>>> num.isdigit()
True
>>> num.isdecimal()
True
>>> num.isnumeric()
True

汉字

 >>> num="二十四"
>>> num.isdigit()
False
>>> num.isdecimal()
False
>>> num.isnumeric()
True

字节(和字符串很像,但在python中不是同一类型)

 >>> num=b''
>>> num.isdigit()
True
>>> num.isdecimal()
Traceback (most recent call last):
File "<stdin>", line , in <module>
AttributeError: 'bytes' object has no attribute 'isdecimal'
>>> num.isnumeric()
Traceback (most recent call last):
File "<stdin>", line , in <module>
AttributeError: 'bytes' object has no attribute 'isnumeric'

 >>> a=b'abc'
>>> type(a)
<class 'bytes'>
>>> a='abc'
>>> type(a)
<class 'str'>

a=b'abc'不是字符串,是字节类型。

"Python的字符串类型是str,在内存中以Unicode表示,一个字符对应若干个字节。如果要在网络上传输,或者保存到磁盘上,就需要把str变为以字节为单位的bytes。"

(http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431664106267f12e9bef7ee14cf6a8776a479bdec9b9000)

4、S.islower() -> bool
    Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise.

字符串里的至少有一个字母且所有的字母为小写

 >>> a='abc'
>>> a.islower()
True
>>> a='abcD'
>>> a.islower()
False
>>> a='abc1'
>>> a.islower()
True
>>> a='abc1-'
>>> a.islower()
True
>>> a='1-'
>>> a.islower()
False

5、S.isupper() -> bool
    Return True if all cased characters in S are uppercase and there is
    at least one cased character in S, False otherwise.

用法参见islower()

6、 S.isprintable() -> bool
    Return True if all characters in S are considered printable in repr() or S is empty, False otherwise.

7、S.isspace() -> bool
    
    Return True if all characters in S are whitespace
    and there is at least one character in S, False otherwise.

字符串至少一个字符,且所有字符都是空格。

 >>> a='abc  '
>>> a.isspace()
False
>>> a[:].isspace()
True

8、  S.istitle() -> bool
    
    Return True if S is a titlecased string and there is at least one
    character in S, i.e. upper- and titlecase characters may only
    follow uncased characters and lowercase characters only cased ones.
    Return False otherwise.

检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写

 >>> a='Hello World !'
>>> a.istitle()
True
>>> a='Hello World ,huhu!'
>>> a.istitle()
False

9、S.join(iterable) -> str
    
    Return a string which is the concatenation of the strings in the
    iterable.  The separator between elements is S.    连接字符.join(可以迭代的字符串)

 >>> a='Hello World ,huhu!'
>>> '-'.join(a)
'H-e-l-l-o- -W-o-r-l-d- -,-h-u-h-u-!'
 >>> a=['hello','world','!']
>>> b='-'
>>> b.join(a)
'hello-world-!'

10、S.ljust(width[, fillchar]) -> str            左对齐
    
    Return S left-justified in a Unicode string of length width. Padding is
    done using the specified fill character (default is a space).
方法返回一个原字符串左对齐,并使用空格或其他字符填充至指定长度的新字符串。如果指定的长度小于原字符串的长度则返回原字符串。

 >>> a='abc'
>>> a.ljust()
'abc '
>>> a.ljust(,'!')
'abc!!!'
>>> a.ljust()
'abc'

11、S.rjust(width[, fillchar]) -> str           右对齐
    
    Return S right-justified in a string of length width. Padding is
    done using the specified fill character (default is a space).

12、S.lower() -> str
    
    Return a copy of the string S converted to lowercase.

13、S.upper() -> str
    
    Return a copy of S converted to uppercase.

 >>> a='Hello World !'
>>> a.lower()
'hello world !'
>>> a.upper()
'HELLO WORLD !'
>>> a
'Hello World !'

14、 S.strip([chars]) -> str    移除头部和尾部字符
    
    Return a copy of the string S with leading and trailing
    whitespace removed.
    If chars is given and not None, remove characters in chars instead.

  S.lstrip([chars]) -> str    移除头部字符
    
    Return a copy of the string S with leading whitespace removed.
    If chars is given and not None, remove characters in chars instead.

  S.rstrip([chars]) -> str    移除尾部字符
    
    Return a copy of the string S with trailing whitespace removed.
    If chars is given and not None, remove characters in chars instead.

 >>> a='  hello world !  '
>>> a.strip()
'hello world !'
>>> a.lstrip()
'hello world ! '
>>> a.rstrip()
' hello world !'
>>> a
' hello world ! '

python3字符串属性(二)的更多相关文章

  1. python3 字符串属性(一)

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

  2. python3 字符串属性(四)

    1. S.partition(sep) -> (head, sep, tail) Search for the separator sep in S, and return the part b ...

  3. python3 字符串属性(三)

    maketrans 和 translate的用法(配合使用) 下面是python的英文用法解释 maketrans(x, y=None, z=None, /) Return a translation ...

  4. mysql 连接命令 表管理 ,克隆表,临时表,字符串属性,设定语句间的分隔符

    连接和断开连接mysql -h host -u user -p (即,连接的主机.用户名和使用的密码).断开输入QUIT (或\q)随时退出: 表管理克隆表注意:create table ... li ...

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

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

  6. (十四)Python3 字符串格式化

    Python3 字符串格式化 字符串的格式化方法分为两种,分别为占位符(%)和format方式.占位符方式在Python2.x中用的比较广泛,随着Python3.x的使用越来越广,format方式使用 ...

  7. NSAttributedString字符串属性类

    //定义一个可变字符串属性对象aStr NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc]initWithStri ...

  8. 字符串属性使用strong的原因

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  9. python3字符串

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

随机推荐

  1. oracle查询当前会话数量

    SELECT a.inst_id,sid,username,event,sql_id,a.PROGRAM FROM gv$session a WHERE a.STATUS='ACTIVE' AND u ...

  2. Eval,Bind,<% %>,<%# %>和<%= %> 笔记

    1.<% %>用来绑定后台代码 如: < % for(int i=0;i<100;i++) { Reaponse.Write(i.ToString()); } %> 2. ...

  3. Redis源码阅读-Dict哈希字典

    Dict和Java中的HashMap很相似,都是数组开链法解决冲突. 但是Redis为了高性能, 有很多比较微妙的方法,例如 数组的大小总是2的倍数,初始大小是4. rehash并不是一次就执行完,而 ...

  4. oracle10g安装问题

    oracle10g的安装还是比较容易的,一直下一步就行了,但是今天安装的时候遇到了一个新问题,在安装的过程中提示提示一些 Configuration Assistant失败刚开始,我直接跳过去,但后面 ...

  5. 验证-- email类型输入框(电子邮件地址)--multiple

    如果需要一个用来填写电子邮件地址的输入框,可以使用email类型.这样浏览器可以帮我们验证格式是否正确,而不需要自己写验证规则.原文:HTML5新控件 - email类型输入框(电子邮件地址) 1,只 ...

  6. GET,POST

    HTTPHTTP(即超文本传输协议)是现代网络中最常见和常用的协议之一,设计它的目的是保证客户机和服务器之间的通信.HTTP 的工作方式是客户端与服务器之间的 “请求-响应” 协议.客户端可以是 We ...

  7. 九度OJ 1207:质因数的个数 (质数)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5939 解决:1926 题目描述: 求正整数N(N>1)的质因数的个数. 相同的质因数需要重复计算.如120=2*2*2*3*5,共有 ...

  8. Ubuntu中安装FTP 服务器自己踩得坑

    12点多了,擦!做个码农真不容易呀! 系统:Ubuntu16.04 安装:FTP 步骤: 1.不管有没有一上来我先卸载: sudo apt-get purge vsftpd 2.再安装:sudo ap ...

  9. information entropy as a measure of the uncertainty in a message while essentially inventing the field of information theory

    https://en.wikipedia.org/wiki/Claude_Shannon In 1948, the promised memorandum appeared as "A Ma ...

  10. Django 之 缓存机制

    Django 缓存机制 缓存介绍 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的用户访问量很大的时候,每一次 ...