Python基础学习四

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python基础学习四相关的知识,希望对你有一定的参考价值。

关于List的学习:

"""More on Lists?
Using Lists as Stacks.
"""

fruits = [‘orange‘, ‘apple‘, ‘pear‘, ‘banana‘, ‘kiwi‘, ‘apple‘, ‘banana‘]

#Return the number of times x appears in the list
print(fruits.count(‘apple‘))
print(fruits.count(‘tangerine‘))

#Return zero-based index in the list of the first item whose value is x.
#list.index(x[, start[, end]])
print(fruits.index(‘kiwi‘, 4))

#Reverse the elements of the list in place.
print("Before reversing ---------------------------------")
print(fruits)
fruits.reverse()
print("After reversing ---------------------------------")
print(fruits)

#Add an item to the end of the list
print("Before appendding ---------------------------------")
print(fruits)
fruits.append(‘grape‘)
print("After appendding ---------------------------------")
print(fruits)

#sort(key=None, reverse=False)
fruits.sort()
print("After sorting ---------------------------------")
print(fruits)

#Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns
# the last item in the list.
fruits.pop()
print("After poping ---------------------------------")
print(fruits)

if ‘apple‘ in fruits:
print("in range")

打印结果:

D:\Python3.6.1\python.exe F:/python_workspace/tutorial/Lists.py
2
0
4
Before reversing ---------------------------------
[‘orange‘, ‘apple‘, ‘pear‘, ‘banana‘, ‘kiwi‘, ‘apple‘, ‘banana‘]
After reversing ---------------------------------
[‘banana‘, ‘apple‘, ‘kiwi‘, ‘banana‘, ‘pear‘, ‘apple‘, ‘orange‘]
Before appendding ---------------------------------
[‘banana‘, ‘apple‘, ‘kiwi‘, ‘banana‘, ‘pear‘, ‘apple‘, ‘orange‘]
After appendding ---------------------------------
[‘banana‘, ‘apple‘, ‘kiwi‘, ‘banana‘, ‘pear‘, ‘apple‘, ‘orange‘, ‘grape‘]
After sorting ---------------------------------
[‘apple‘, ‘apple‘, ‘banana‘, ‘banana‘, ‘grape‘, ‘kiwi‘, ‘orange‘, ‘pear‘]
After poping ---------------------------------
[‘apple‘, ‘apple‘, ‘banana‘, ‘banana‘, ‘grape‘, ‘kiwi‘, ‘orange‘]
in range

























































以上是关于Python基础学习四的主要内容,如果未能解决你的问题,请参考以下文章

验证码逆向专栏某验四代文字点选验证码逆向分析

实验四代码评审

《Python学习之路 -- Python基础之切片》

python基础学习篇章一

python学习基础篇

python基础学习-字符串