畅享聊:python切片及数据类型转换
off999 2024-09-13 13:36 25 浏览 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中的两个内置函数id()和type()
-
id()>>>id(3)2531362761072>>>id(3.222222)2531397393680>>>id(3.0)25313...
- python 函数中,如何将另一个函数作为参数传递
-
python函数中,如何将另一个函数作为参数传递,类似C#委托defadd(a,b):"""这是一个简单的加法函数,接受两个参数并返回它们的和。""...
- Python性能暴涨10倍的终极指南:7个核心技巧+代码压缩秘籍
-
提升Python程序运行性能,使代码运行更流畅更快,以及压缩代码,减小代码大小,下面的方法仅供大家参考,有什么更好的方法在评论区说说。1.使用NumPy/SciPy替代纯Python循环...
- Python 匿名函数(Lambda 函数)详解
-
匿名函数(AnonymousFunction),在Python中称为lambda函数,是一种不需要使用def关键字定义的小型函数。它主要用于简化代码,特别适合需要函数对象的地方。1.基...
- Python学习笔记 | 匿名函数lambda、映射函数map和过滤函数filter
-
什么是匿名函数?定义:没有函数名的自定义函数场景:函数体非常简单,使用次数很少,没有必要声明函数,通常搭配高阶函数使用。高阶函数是能够把函数当成参数进行传递的函数,如:映射函数map和过滤函数fil...
- python练习:自定义函数调用:商品购物实例
-
1、商品录入dict_myshanpin_iof={101:{"商品名称":"毛毛熊","单价":25},102:{"商品名称":...
- Python中如何使用Lambda函数(lambda在python中的用法)
-
Python和其他编程语言一样,都在其语法中添加了lambda函数,Pythonlambda是匿名函数,比常规Python自定义函数有更简洁的语法。虽然Lambda语法在开始时可能会觉得有点混乱,...
- 8-Python内置函数(python内置函数代码)
-
Python提供了丰富的内置函数,这些函数可以直接使用而无需导入任何模块。以下是一些常用的内置函数及其示例:1-print()1-1-说明输出指定的信息到控制台。1-2-例子2-len()2-1-说...
- 用Python进行函数式编程(python函数程序)
-
什么是函数式编程?函数式程序设计是一种编程范例,它把计算当作数学函数的评价,避免状态和可变数据。换句话说,函数编程(FunctionalProgramming,FP)促进没有副作用和不变变量的代码。它...
- python 函数进阶(python如何进阶)
-
1.有名函数和匿名函数#该函数有名称,名称是adddefadd(x,y):returnx+y#改函数没有名称属于匿名函数,也叫lambda表达式lambda_add...
- python自学者的分享:自定义函数、参数作用域、匿名函数、装饰器
-
#自定义新函数函数名newhsdefnewhs(a,b=1):#b的默认值为1,在没有传入b值时,采用默认值,,默认值参数不能放前边returna-bprint(newh...
- Python 函数式编程的 8 大核心技巧,不允许你还不会
-
函数式编程是一种强调使用纯函数、避免共享状态和可变数据的编程范式。Python虽然不是纯函数式语言,但提供了丰富的函数式编程特性。以下是Python函数式编程的8个核心技巧:1.纯函数(...
- 零基础到发布:手把手教你创建并分发 Python 自定义库
-
作为程序员,我们经常依赖各种外部库来解决不同的问题。这些库由技术娴熟的开发者创建,为我们提供了节省时间和精力的解决方案。但你是否曾想过:“我也能创建属于自己的自定义库吗?”答案是肯定的!本文将为你详细...
- 打工人学Python:(七)自定义函数,打造自己的武器库
-
从一个简单的函数开始#!/usr/bin/envpython#-*-encoding:utf-8-*-'''@Purpose:Wordcount@...
- 肖sir_python自定义函数format、zip函数
-
python自定义函数一、常见的自定义函数已经学过的函数:list、print、set、str、type、tuple、dict、range、input等今天学的函数:format二、实战讲解(一)f...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python自定义函数 (53)
- python进度条 (54)
- python的for循环 (56)
- python串口编程 (60)
- python写入txt (51)
- python读取文件夹下所有文件 (59)
- java调用python脚本 (56)
- python操作mysql数据库 (66)
- python字典增加键值对 (53)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python qt (52)
- python人脸识别 (54)
- python多态 (60)
- python命令行参数 (53)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- centos7安装python (53)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)