python中的isprintable函数_函数解析——python学习第三次总
.str字符串类型(⼆)
1.  isalpha  判断⽬标字符串中是否只含字母
表达式  str.isalpha()  ==>  bool
⽰例:
1 a = 'alex'
2 v =a.isalpha()
3 print(v)
# 输出
# True
源码:
1 def isalpha(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is an alphabetic string, False otherwise.4
5 A string is alphabetic if all characters in the string are alphabetic and there
6 is at least one character in the string.
7 """
源码
2.  isdecimal
isdigit  都是⽤来判断⽬标字符串是否是数字,上⾯这个是在⼗进制范围内,下⾯这个不光能判断纯⽂本,还能判断复杂符号。
表达式  str.isdecimal()  ==>  bool
str.isdigit()  ==>  bool
⽰例:
1 a = '②'
2 b =a.isdecimal()
3 c =a.isdigit()
4 print(b,c)
# 输出
# false true
源码:
1 def isdecimal(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is a decimal string, False otherwise.4
5 A string is a decimal string if all characters in the string are decimal and
6 there is at least one character in the string.
7 """ isdecimal
1 def isdigit(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is a digit string, False otherwise.4
5 A string is a digit string if all characters in the string are digits and there
6 is at least one character in the string.
7 """ isdigit
3.  isidentifier  判断⽬标字符串是否只含数字、字母、下划线,即判断出是否是属于变量名称。
表达式  str.isidentifier()  ==>  bool
⽰例:
1 print('def_class123'.isidentifier())
# 输出
# true
源码
1 def isidentifier(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is a valid Python identifier, False otherwise.4
5 Use keyword.iskeyword() to test for reserved identifiers such as "def" and
6 "class".
7 """
源码
4.  isspace  ⽬标字符串中是否只含有空格
表达式  str.isspace()  ==>  bool
⽰例:
1 print(' '.isspace())
# 输出
# true
源码:
1 def isspace(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is a whitespace string, False otherwise.4
5 A string is whitespace if all characters in the string are whitespace and there
6 is at least one character in the string.
isalpha 函数7 """源码
5.  islower  判断⽬标字符串中的所有英⽂字母是否是⼩写
表达式  str.islower()  ==>  bool
⽰例:
1 print('adsf_②123贰⼆'.islower())
# 输出
# TRUE
源码:
1 def islower(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is a lowercase string, False otherwise.4
5 A string is lowercase if all cased characters in the string are lowercase and
6 there is at least one cased character in the string.
7 """
源码
6.  isnumeric  判断⽬标字符串是否只含数字(含字符数字)
表达式  str.isnumeric()  ==>  bool
⽰例:
1 print('②Ⅱ123贰⼆'.isnumeric())
# 输出
# true
源码:
1 def isnumeric(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is a numeric string, False otherwise.4
5 A string is numeric if all characters in the string are numeric and there is at
6 least one character in the string.
7 """
源码
7.  isprintable  判断字符串是否可打印(是否可以打印决定于⾥⾯是否有不可显⽰字符。换⾔之⾥⾯不可复⽤函数,需先输出结果)
表达式  str.isprintable()  ==>  bool
⽰例:
1 print('er⼆贰②——'.isprintable())
# 输出
# TRUE
源码:
1 def isprintable(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is printable, False otherwise.4
5 A string is printable if all of its characters are considered printable in
6 repr() or if it is empty.
7 """
源码
8.  istitle  ⽬标字符串中是否是标题(即满⾜每个单词⾸字母⼤写)
表达式  str.istitle()  ==>  bool
⽰例:
1 print('Return True if the string is a valid Python identifier'.istitle())
# 输出
# false
源码:
1 def istitle(self, *args, **kwargs): #real signature unknown
2 """
3 Return True if the string is a title-cased string, False otherwise.4
5 In a title-cased string, upper- and title-case characters may only
6 follow uncased characters and lowercase characters only cased ones.
7 """
源码
9.  title  将⽬标字符串转换为标题格式(即转换为每个单词⾸字母⼤写)
表达式:  str.title()  ==>  str
⽰例:
1 print('Return True if the string is a valid Python identifier'.title())
# 输出
# Return True If The String Is A Valid Python Identifier
源码:
1 def title(self, *args, **kwargs): #real signature unknown
2 """
3 Return a version of the string where each word is titlecased.4
5 More specifically, words start with uppercased characters and all remaining
6 cased characters have lower case.
7 """
源码
10.  join  将设置字符插⼊⽬标字符串中每个字符中间
表达式  str.join(iterable)  ==>  str
⽰例:
1 print('-'.join('你是风⼉我是沙'))
# 输出
# 你-是-风-⼉-我-是-沙
源码:
1 def join(self, ab=None, pq=None, rs=None): #real signature unknown; restored from __doc__
2 """
3 Concatenate any number of strings.4
5 The string whose method is called is inserted in between each given string.
6 The result is returned as a new string.
7
8 Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
9 """
源码
11.  ljust  原有字符串在左⽅,右⽅添加指定字符
表达式  str.ljust(width,fillchar)  ==>  str
width  总格式化宽度
fillchar  插⼊字符
⽰例:
1 print('alex'.ljust(20,'$'))
# 输出
# alex$$$$$$$$$$$$$$$$
源码:
1 def ljust(self, *args, **kwargs): #real signature unknown
2 """
3 Return a left-justified string of length width.4
5 Padding is done using the specified fill character (default is a space).
6 """
源码
12.  rjust  原有字符串在右⽅,左⽅添加指定字符
表达式  str.rjust(width,fillchar)  ==>  str
width  总格式化宽度
fillchar  插⼊字符
⽰例:
1 print('alex'.rjust(20,'$'))
# 输出
# $$$$$$$$$$$$$$$$alex
源码:
1 def rjust(self, *args, **kwargs): #real signature unknown
2 """

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。