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

Python list methods All In One

作者:互联网

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:xgqfrms@xgqfrms.xyz
"""

"""
  /**
   *
   * @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
来源: https://www.cnblogs.com/xgqfrms/p/16599715.html