首页 > 编程语言 >Python list methods All In One

Python list methods All In One

时间:2022-08-18 18:36:06浏览次数:82  
标签:__ arr methods Python list xgqfrms print find

Python list methods All In One

Python 3


#!/usr/bin/env python3
# coding=utf-8

__author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
  Copyright (c) 2012-2050, xgqfrms; mailto:[email protected]
"""

"""
  /**
   *
   * @author xgqfrms
   * @license MIT
   * @copyright xgqfrms
   * @created 2022-08-17
   *
   * @description
   * @augments
   * @example
   * @link
   *
  */
"""

# python 模版 

join

arr = ['a', 'b', 'c']

strs = ''.join(arr)
print(strs)
# abc

_strs = '-'.join(arr)
print(_strs)
# a_b_c

reverse

arr = ['a', 'b', 'c']

# reverse 没有返回新 list, 没有返回值 ✅ ,  None
# arr.reverse()

print(arr.reverse())
# None

print(arr)
# cba


string find

arr = ['a', 'b', 'c']
s = 'b'

# AttributeError: 'list' object has no attribute 'find' ❌
if(arr.find(s) > -1):
  print(True)

print(arr.find('x'))

ss = 'anc'
s = 'b'

if(ss.find(s) > -1):
  print(True)

print(ss.find('x'))

list & string index


ss = 'anc'
s = 'b'

if(ss.find(s) > -1):
  print(True)

print(ss.find('x'))
# -1
print(ss.index('x'))
# ValueError: substring not found ❌

pop


append


remove


count


sort


clear


copy


insert


extend


range

# 左闭右开 [begin, end),  步长 step
steps = list(range(0, 10, 3))
# [0, 3, 6, 9]

slice


for...in


refs

https://www.programiz.com/python-programming/methods/string/join

https://www.runoob.com/python3/python3-list.html

https://stackoverflow.com/questions/493819/why-is-it-string-joinlist-instead-of-list-joinstring



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载

标签:__,arr,methods,Python,list,xgqfrms,print,find
From: https://www.cnblogs.com/xgqfrms/p/16599715.html

相关文章

  • Redis 数据类型list以及使用场景
    简介: Redis数据类型list以及使用场景数据存储需求:存储多个数据,并对数据进入存储空间的顺序进行区分需要的存储结构:一个存储空间保存多个数据,且通过数据可以体现进入顺......
  • python菜鸟学习: 9. 文件操作
    #-*-coding:utf-8-*-importsys,time#读文件:一次性读取所有内容#r=readf=open("singe.txt",'r',encoding="utf-8").read()print(f)#写文件,覆盖原来的文件#w=wr......
  • python 读取.pkl.gz文件
    1importpandasaspd2importsix.moves.cPickleascPickle3importgzip45filePath='./a/data.pkl.gz'6f=gzip.open(filePath,'rb')7df=pd.D......
  • Python进阶篇02-函数
    一、常规函数的定义函数函数就是一段组织好的、可以重复使用的代码块。比如在你写的某个.py文件中,需要频繁的计算面积,这样我们会有很多相似、重复的代码,在这种情况下,我......
  • Python 创建虚拟环境
    桌面建立一个文件夹,假设为tor打开cmdcddesktopcdtor假设python没有  pipenv包,则pip3installpipenv假设tor文件夹内没有虚拟环境,即没有pipfiel及p......
  • python中输出两条长度一致序列碱基不同的个数
     001、方法1root@PC1:/home/test#lstest.pyroot@PC1:/home/test#cattest.py##测试程序#!/usr/bin/pythonstr1="GAGCCTACTAACGGGAT"......
  • Python报错:ImportError cannot import name 'imresize'
    原文链接Python出现错误:ImportError:cannotimportname'imresize'解决方案首先安装pillow:pipinstallpillow然后安装scipy早期版本。高级版scipy本不再......
  • Python 数据类型及转换
    Python数据类型及转换说明:Python每一个变量在使用前都要赋值,每个变量都有一个数据类型,之前说的type()函数可以查看变量的类型。Python常见的数据类型有:Number(数字)、Strin......
  • python 执行shell 日志 输出
    一、python执行shell实时打印到屏幕上fromsubprocessimportPopen,PIPE,STDOUTmove_data="cmd_val"defexec_command(command):move_path=Popen(com......
  • 发现一个舔狗神器,Python真的太厉害了,自动下载妹子视频...
    兄弟们,现在短视频主播好看的妹子太多了,有时候遇到自己喜欢的,虽然点了赞或者收藏了,但是万一主播把视频隐藏下架了呢?所以今天咱们就用Python来把这些好看的视频统统保存......