技术标签: 下列不是python内置函数的是
此处列举的是python中常用的内置函数,是在工作中用到的.
Python enumerate() 函数
enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。
语法
以下是 enumerate() 方法的语法:
enumerate(sequence, [start=0])
参数
sequence -- 一个序列、迭代器或其他支持迭代对象。
start -- 下标起始位置。
返回值
返回 enumerate(枚举) 对象。
实例
以下展示了使用 enumerate() 方法的实例:
li = ['car','bus','apple','xiaomi']
enumerate(li)list(enumerate(li))
[(0, 'car'), (1, 'bus'), (2, 'apple'), (3, 'xiaomi')]
list(enumerate(li,start=1)) ##下标从 1开始
[(1, 'car'), (2, 'bus'), (3, 'apple'), (4, 'xiaomi')]
普通的for循环列出数据和下标对应关系.
#!/usr/bin/env python#coding:utf-8
product_list= ['C','Java','C++','Python','Php','Ruby','Go']for item inproduct_list:
index= product_list.index(item) #使用列表的index方法,取出字符对应的下标值.
print(index,item)---------------------------------------------0 C1Java2 C++
3Python4Php5Ruby6 Go
第二种方法:
#!/usr/bin/env python#coding:utf-8
i=0
product_list= ['C','Java','C++','Python','Php','Ruby','Go']for item inproduct_list:print(i,product_list[i])
i+= 1
-------------------------------------------0 C1Java2 C++
3Python4Php5Ruby6 Go
for 循环使用 enumerate 函数
#定义一个变量,返回为元组数据
#!/usr/bin/env python#coding:utf-8
product_list = ['C','Java','C++','Python','Php','Ruby','Go']for item inenumerate(product_list):print(item)------------------------------------------------------------(0,'C')
(1, 'Java')
(2, 'C++')
(3, 'Python')
(4, 'Php')
(5, 'Ruby')
(6, 'Go')#定义两个变量,返回为下标和元素的对应关系
product_list = ['C','Java','C++','Python','Php','Ruby','Go']for index,item inenumerate(product_list):print(index,item)-----------------------------------------0 C1Java2 C++
3Python4Php5Ruby6 Go
定义下标起始位置,用start参数.
#!/usr/bin/env python#coding:utf-8
product_list= ['C','Java','C++','Python','Php','Ruby','Go']for index,item in enumerate(product_list,start=1):print(index,item)------------------------------
1C2Java3 C++
4Python5Php6Ruby7 Go
Python int() 函数
int() 函数用于将一个字符串或数字转换为整型
语法
以下是 int() 方法的语法:
class int(x, base=10)
参数
x -- 字符串或数字。
base -- 进制数,默认十进制。
返回值
返回整型数据。
>>> int(3)3
>>> int(3.6)3
Python sorted() 函数
sorted() 函数对所有可迭代的对象进行排序操作。
Python len()方法
Python len() 方法返回对象(字符、列表、元组等)长度或项目个数。
实例:
>>>str = "runoob"
>>> len(str) #字符串长度
6
>>> l = [1,2,3,4,5]>>> len(l) #列表元素个数
5
Python id() 函数
id() 函数用于获取对象的内存地址
以下实例展示了 id 的使用方法:
>>>a = 'runoob'
>>>id(a)4531887632
>>> b = 1
>>>id(b)140588731085608
便利贴--7{OpenLayers,vue项目1,添加地图的路径和标点数据}
String Agent = request.getHeader("User-Agent");StringTokenizer st = new StringTokenizer(Agent,";");st.nextToken();//得到用户的浏览器名String userbrowser = st.nextToken();//得到用户的操作系统名String useros = st.nextToke
然后将此清空输入以代码CREATETRIGGERafter_deleteAFTERDELETEONFlagsBEGININSERTORREPLACEINTOFlags(packageName,version,flagType,partitionId,user,name,stringVal,committed)VALUES("com.google.android...
Battle CityMany of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now.What we are discussing is a simple edition of this game. Given...
首先看一下一个SpringBoot应用的启动类:@SpringBootApplicationpublic class ColdTraceWebApplication { public static void main(String[] args) { SpringApplication.run(ColdTraceWebApplication.class, args); }}一、创建一个SpringApplication对象 public Sprin
写一个简单的服务var http=require('http')var server=http.createServer()server.listen(8080,'localhost');server.on('request',function (req,res) {//req:客户端请求的信息,res:服务端返回的响应 res.write("<h1>hello</h1>");
原文链接:http://tecdat.cn/?p=8448文本生成是NLP的最新应用程序之一。深度学习技术已用于各种文本生成任务,例如写作诗歌,生成电影脚本甚至创作音乐。但是,在本文中,我们将看到一个非常简单的文本生成示例,其中给定输入的单词字符串,我们将预测下一个单词。我们将使用莎士比亚著名小说《麦克白》的原始文本,并根据给定的一系列输入单词来预测下一个单词。完成本文之后,您将能......
下载地址https://www.sublimetextcn.com/3/根据自己的电脑下载本例下载的安装过程双击安装不停的下一步运行测试
package com.demo;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;impo...
0.9300.71555.31201018001.130973355桩长21.3mN(KN)φfc(kN/m2)Ap(m2)f’s(kN/m2)A’s(m2)桩直径(m2)11518.963620.7119001.1309733553000000.0160849541.2标准值19006.29KN单桩承载力设计计算(建筑桩基技术规范08版)根据《建筑桩基技术规范》(JGJ94—2008),单桩竖...
C语言中的memset在C/C++中,有一个memset函数,常常用来清空一段内存。#include &lt;string.h&gt;// 将s的前n个字节用c填充void *memset(void *s, int c, size_t n);// 用法举例int arr[100];// 将数组内存全部置为0memset(&amp;arr, 0, sizeof(arr));由于...
SOCKET()我们使用系统调用socket()来获得文件描述符:#include<sys/types.h>#include<sys/socket.h>int socket(int domain,int type,int protocol);第一个参数domain设置为“AF_INET”。第二个参数是套接口的类型:SOCK_STREAM或SOCK_DGRAM。第三个参数...