SuooL's Blog

蛰伏于盛夏 藏华于当春

python 基础笔记

引言

此处用来放写代码过程中看到的函数用法笔记及一些简单问题的解决方法。

内建库函数

shuffle() 函数

shuffle() 方法将序列的所有元素随机排序,属于 random模块,该函数无返回值。
使用示例如下:

1
2
3
4
5
6
7
# -*- coding: UTF-8 -*-

import random

list = [20, 16, 10, 5];
random.shuffle(list)
print ("随机排序列表 : ", list)

output:
1
随机排序列表 :  [16, 5, 10, 20]

split() 方法

str.split(str="", num=string.count(str)).
通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则分隔 num+1 个子字符串.
返回值是一个列表,返回分割后的字符串列表。

泡面一杯