首页 > 编程语言 >python之数据类型

python之数据类型

时间:2024-01-18 17:22:27浏览次数:30  
标签:Return sub format python 数据类型 str print

字符串详解                                                                                 

1.center         
def center(self, *args, **kwargs): # real signature unknown
"""
Return a centered string of length width.

Padding is done using the specified fill character (default is a space).
"""
pass
翻译:1.返回长度未width(第一个参数)的居中字符串
2.使用指定的填充字符(第二个参数,默认为空格)进行填充
1 #!/usr/bin/python
2 str='wo ai bei Jing Tian an men'
3 print(str.center(100,'-'))#据中打印并以-填充到100个字符
View Code
2.capitalize
def capitalize(self, *args, **kwargs): # real signature unknown
"""
Return a capitalized version of the string.

More specifically, make the first character have upper case and the rest lower
case.
"""
pass
翻译:1.返回字符串一个大写版本
2.详细一点来说就是是每个字符串首字母大写,其余小写
1 #!/usr/bin/python
2 str='wo ai bei Jing Tian an men'
3 print(str.capitalize())#首字母大写
View Code

 3.upper

def upper(self, *args, **kwargs): # real signature unknown
""" Return a copy of the string converted to uppercase. """
翻译:1.返回转换为大写字母的副本
1 #!/usr/bin/python
2 str='wo ai bei Jing Tian an men'
3 print(str.upper())
View Code

4.lower

def lower(self, *args, **kwargs): # real signature unknown
""" Return a copy of the string converted to lowercase. """
pass
翻译:返回转换为小写字母的副本
1 #!/usr/bin/python
2 str='wo ai bei Jing Tian an men'
3 print(str.lower())
View Code

5.count

def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.count(sub[, start[, end]]) -> int

Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation.
"""
return 0
翻译:语法s.count(统计的字母,开始序号哦,结束序号)--》返回值是整型
返回字符sub在范围【开始-结束】间的不重复出现的次数,可选参数开始和结束可解释为切片表示法
1 #!/usr/bin/python
2 str='wo ai beii Jing Tian an men'
3 print(str.count('i',0,10))
View Code

 6.find

def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
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 and end are interpreted as in slice notation.

Return -1 on failure.
"""
return 0
翻译:语法s.find(查找的字符sub,开始位置,结束位置)-->返回整型
返回字符sub在范围内被发现的最小的索引,可选参数开始位置和结束位置可解释为切片表示法
1 #!/usr/bin/python
2 str='wo ai beii Jing Tian an men'
3 print(str.find('i'))
View Code

7.replace

def replace(self, *args, **kwargs): # real signature unknown
"""
Return a copy with all occurrences of substring old replaced by new.

count
Maximum number of occurrences to replace.
-1 (the default value) means replace all occurrences.

If the optional argument count is given, only the first count occurrences are
replaced.
"""
pass
翻译:返回字符串所有出现的旧值被新值覆盖的副本
count 出现最大数被替代,-1(默认值)意思是所有出现的都被替代。
如果可选参数被给出,那么只替换第一次出现的值
语法:s.replace(旧值,新值,出现个数(从左边开始)默认-1为所有替换)
1 #!/usr/bin/python
2 str='wo ai beii Jing Tian an men'
3 print('replace用法:',str.replace('i','I',1))
View Code

8.format

def format(self, *args, **kwargs): # known special case of str.format
"""
S.format(*args, **kwargs) -> str

Return a formatted version of S, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}').
"""
pass
翻译:将字符串里面用{}的替换为args或kwargs替换
1 #!/usr/bin/python
2 str='{} ai bei Jing Tian an men'
3 print(str.format('wo'))
4 str='name is {},age is {} '
5 print('format用法:',str.format('ll',22))#按位置参数赋值
6 str='name is {1},age is {0} '
7 print('format用法:',str.format(22,'ll'))#按位置参数赋值
View Code

9.format_map

def format_map(self, mapping): # real signature unknown; restored from __doc__
"""
S.format_map(mapping) -> str

Return a formatted version of S, using substitutions from mapping.
The substitutions are identified by braces ('{' and '}').
"""
return ""
翻译:将字符串里面用{}的替换为map
1 #!/usr/bin/python
2 str='name is {name},age is {age} '
3 print(str.format_map({'name':'ll','age':22}))
View Code

未完待续。。。。。。                                                

标签:Return,sub,format,python,数据类型,str,print
From: https://www.cnblogs.com/simple-girl/p/17972848

相关文章

  • Python_python读写图片以及对应的库比较
    图片读写通过numpy来做数据计算的沟通JPEG是一种有损格式, 图像PNG,是一种无损格式cv2.imdecode()作用是将图像数据从存储格式中解析出来并转化为OpenCV中的图像格式 imdecode得到的影像波段顺序是RGBnp.fromfile将文本或二进制文件中数据构造成数组 cv2.imencod......
  • WhisperService 多GPU python
    如何实现“WhisperService多GPUPython”作为一名经验丰富的开发者,你将教会一位刚入行的小白如何实现“WhisperService多GPUPython”。下面是整个实现过程的步骤:步骤说明步骤一导入必要的库并设置GPU步骤二加载数据步骤三构建模型步骤四配置训练参数......
  • python数据结构中实现队列的几种方法
    1.list实现enqueueappend()dequeuepop(0)或enqueueinsert(0,item)dequeuepop()MAX_SIZE=100classMyQueue1(object):"""模拟队列"""def__init__(self):self.items=[]self.size=0defis_empty(s......
  • Python使用__dict__查看对象内部属性的名称和值
    1、定义一个类classMyObj:def__init__(self,name,age):self.name=nameself.age=agedefmyFunc(self):passmo=MyObj('Boby',24)print(mo)print(mo.__dict__)#结果<__main__.MyObjobjectat0x000000815C36451......
  • python编程中break pass continue这三个有什么区别?
    在Python编程中,break、pass和continue是三种不同的控制流语句,它们各自有不同的用途和行为:(以下内容由百度文心一言生成)   break:       break语句用于终止循环的执行。当程序执行到break语句时,会立即跳出当前循环,不再执行循环内的剩余代码,而是继续执行循环之后的代......
  • python llama_index
    PythonLlamaIndexIntroductionPythonisapopularprogramminglanguageknownforitssimplicityandreadability.Ithasavastecosystemoflibrariesandframeworksthatmakeitsuitableforawiderangeofapplications,fromwebdevelopmenttodataana......
  • python 安装 llama_index
    Python安装llama_index简介在进行数据分析和机器学习的过程中,我们经常需要对数据进行索引和检索。其中,llama_index是一个强大的Python库,用于快速构建和管理索引。它提供了各种功能,包括全文搜索、近似搜索、范围搜索等。本文将向您介绍如何安装和使用llama_index。安装要安装l......
  • python迭代器和生成器
    迭代器:定义:迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束。迭代器只能往前不会后退。迭代器有两个基本的方法:iter()和next()。字符串,列表或元组对象都可用于创建迭代器:ex:#!/usr/bin/python3list=[1,2,3,4]it=iter(list)#创建迭代器对......
  • python的whisper工具包
    实现Python的Whisper工具包作为一名经验丰富的开发者,你需要教一位刚入行的小白如何实现Python的Whisper工具包。下面是整个实现的步骤概述:确定需求:首先需要明确Whisper工具包的功能和用途,以便为其设计合适的代码结构。安装必要的库:使用pip命令安装Python的相关库,如numpy、panda......
  • Python whisper识别
    Pythonwhisper识别Pythonwhisper识别是一个用于语音识别的开源Python库。它基于Google的语音识别API,通过将语音转换为文本,实现对语音数据的处理和分析。Pythonwhisper识别可以应用于各种场景,例如语音助手、语音命令控制和语音转写等。安装Pythonwhisper识别要使用Pythonwh......