百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

畅享聊:python切片及数据类型转换

off999 2024-09-13 13:36 20 浏览 0 评论

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是LearningYard新学苑。今天小编为你带来

畅享聊:Python序列切片及数据类型转换

欢迎您的访问!

Share interests, spread happiness, increase knowledge, and leave beautiful!

Dear you, this is LearningYard Academy.

Today, the editor brings you

Enjoy chatting: Python sequence slicing and data type conversion

welcome your visit!


Python的世界真丰富,今天小编带给大家的是关于Python序列的一些知识与操作。切片操作,先看看语法结构:

序列[start:end:step]

简单说明:

1.start表示切片的开始位置(包括开始位置),若不指定则默认为0

2.end表示结束为止(不包括结束位置),若不指定则默认为序列长度

3.step表示步长,若不指定则默认为1

整体如图


The world of Python is really rich. Today's small compilation brings you some knowledge and operations about Python sequences. For slicing, first look at the syntax structure:

Sequence [start: end: step]

Brief description:

1. Start indicates the starting position of the slice (including the starting position). If not specified, it defaults to 0

2. End indicates the end (excluding the end position). If not specified, it defaults to the sequence length

3. Step represents step size. If not specified, it defaults to 1

As shown in the figure



下面的这张图能够帮助理解“步长”(ps:#表示注销该部分)

The following figure can help to understand the "step size" (ps: # means to log off this part)


序列的加法与乘法:

Addition and multiplication of sequences:



这是一些序列相关的操作符和函数:

Here are some sequence related operators and functions:


看到这些多少有点心痒痒,毕竟动手实践是编程的乐趣所在嘛,这也有助于熟悉掌握。ps:w=’Hellowworld’

It's a bit itchy to see these. After all, hands-on practice is the fun of programming, which is also conducive to familiarity and mastery. ps:w=’Hellowworld’

大家可以发现,输出w的最大值是“w”,输出的最小值“d”。于是就很疑惑了,为什么会是这俩字母呢,其实每个字母都对应着一个Unicode码。这就是根据Unicode码来排的大小。


下面这些是一些基础的Python Number类型转换:

1.int(x[,base])将x转化为一个整数

2.long(x[,base])将x转化为一个长整数

3.float(x)将x转化为一个浮点数

4.str(x)将x转化为一个字符串

5.repr(x)将x转化为表达式字符串

6.eval(str)用来计算字符串中的有效python表达式,并返回一个对象

7.tuples(s)将序列s转化为一个元组

8.list(s)将序列s转化为一个列表

9.chr(x)将一个整数转化为一个字符

10.unichr(x)将一个整数转化为一个Unicode字符

11.ord(x)将一个字符转化为它的整数值

12.hex(x)将一个整数转化为一个十六进制的字符串

13.oct(x)讲一个整数转化为一个八进制的字符串


You can find that the maximum value of output w is "w" and the minimum value of output is "d". Then I was very confused. Why are these two letters? In fact, each letter corresponds to a Unicode code. This is the size according to the Unicode code.

The following are some basic Python Number type conversions:

1. int (x [, base]) converts x to an integer

2. long (x [, base]) converts x to a long integer

3. float (x) converts x to a floating point number

4. str (x) Converts x to a string

5. repr (x) Converts x to an expression string

6. eval (str) is used to calculate the valid python expression in the string and return an object

7. tuples (s) convert sequence s into a tuple

8. list (s) Converts sequence s into a list

9. chr (x) Converts an integer to a character

10. unichr (x) Converts an integer to a Unicode character

11. ord (x) Converts a character to its integer value

12. hex (x) Converts an integer to a hexadecimal string

13. oct (x) is used to convert an integer into an octal string


今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天,

祝您今天过得开心快乐!

That's it for today's sharing.


If you have a unique idea about today’s article,


Welcome to leave us a message,


Let us meet tomorrow,


I wish you a happy day today!


本文由learningyard新学苑原创,如有侵权,请联系我们。


参考资料:b站视频,菜鸟教程

部分图片来源:b站视频截图

翻译来源:百度翻译


文字&排版|calm

审核|闫庆红

相关推荐

Python 数据分析——利用Pandas进行分组统计

话说天下大势,分久必合,合久必分。数据分析也是如此,我们经常要对数据进行分组与聚合,以对不同组的数据进行深入解读。本章将介绍如何利用Pandas中的GroupBy操作函数来完成数据的分组、聚合以及统计...

python数据分析:介绍pandas库的数据类型Series和DataFrame

安装pandaspipinstallpandas-ihttps://mirrors.aliyun.com/pypi/simple/使用pandas直接导入即可importpandasas...

使用DataFrame计算两列的总和和最大值_[python]

【如果对您有用,请关注并转发,谢谢~~】最近在处理气象类相关数据的空间计算,在做综合性计算的时候,DataFrame针对每列的统计求和、最大值等较为方便,对某行的两列或多列数据进行求和与最大值等的简便...

8-Python内置函数

Python提供了丰富的内置函数,这些函数可以直接使用而无需导入任何模块。以下是一些常用的内置函数及其示例:1-print()1-1-说明输出指定的信息到控制台。1-2-例子2-len()2-1-说...

Python中函数式编程函数: reduce()函数

Python中的reduce()函数是一个强大的工具,它通过连续地将指定的函数应用于序列(如列表)来对序列(如列表)执行累积操作。它是functools模块的一部分,这意味着您需要在使用它之...

万万没想到,除了香农计划,Python3.11竟还有这么多性能提升

众所周知,Python3.11版本带来了较大的性能提升,但是,它具体在哪些方面上得到了优化呢?除了著名的“香农计划”外,它还包含哪些与性能相关的优化呢?本文将带你一探究竟!作者:BeshrKay...

最全python3.11版12类75个内置函数大全

获取全部内置函数:importbuiltins#导入模块yc=[]#异常属性nc=[]#不可调用fn=[]#内置函数defll(ty=builtins):...

软件测试笔试题

测试工程师岗位,3-5年,10-14k1.我司有一款产品,类似TeamViewer,向日葵,mstsc,QQ远程控制产品,一个PC客户端产品,请设想一下测试要点。并写出2.写出常用的SQL语句8条,l...

备战各大互联网巨头公司招聘会,最全Python面试大全,共300题

前言众所周知,越是顶尖的互联网公司在面试这一part的要求就越高,需要你有很好的技术功底、项目经验、一份漂亮的简历,当然还有避免不了的笔试过关。对于Python的工程师来说,全面掌握好有关Python...

经典 SQL 数据库笔试题及答案整理

马上又是金三银四啦,有蛮多小伙伴在跳槽找工作,但对于年限稍短的软件测试工程师,难免会需要进行笔试,而在笔试中,基本都会碰到一道关于数据库的大题,今天这篇文章呢,就收录了下最近学员反馈上来的一些数据库笔...

用Python开发日常小软件,让生活与工作更高效!附实例代码

引言:Python如何让生活更轻松?在数字化时代,编程早已不是程序员的专属技能。Python凭借其简洁易学的特点,成为普通人提升效率、解决日常问题的得力工具。无论是自动化重复任务、处理数据,还是开发个...

太牛了!102个Python实战项目被我扒到了!建议收藏!

挖到宝了!整整102个Python实战项目合集,从基础语法到高阶应用全覆盖,附完整源码+数据集,手把手带你从代码小白变身实战大神!这波羊毛不薅真的亏到哭!超全项目库,学练一站式搞定这份资...

Python中的并发编程

1.Python对并发编程的支持多线程:threading,利用CPU和IO可以同时执行的原理,让CPU不会干巴巴等待IO完成。多进程:multiprocessing,利用多核CPU...

Python 也有内存泄漏?

1.背景前段时间接手了一个边缘视觉识别的项目,大功能已经开发的差不多了,主要是需要是优化一些性能问题。其中比较突出的内存泄漏的问题,而且不止一处,有些比较有代表性,可以总结一下。为了更好地可视化内存...

python爬虫之多线程threading、多进程、协程aiohttp批量下载图片

一、单线程常规下载常规单线程执行脚本爬取壁纸图片,只爬取一页的图片。importdatetimeimportreimportrequestsfrombs4importBeautifu...

取消回复欢迎 发表评论: