shuffle()

作者: 轩爱青 | 来源:发表于2018-06-29 09:34 被阅读0次

2018-06-29

###shuffle() 方法将序列的所有元素随机排序。

#需要导入 random 模块,然后通过 random 静态对象调用该方法

import random

list = [123,456,789,'zy','rd'] #序列

random.shuffle(list)

print(list)

#python访问字符串中的值

#Python不支持单字符类型,单字符也在Python也是作为一个字符串使用。

#Python访问子字符串,可以使用方括号来截取字符串

var1 = 'welcome to python world'

print('val[5]:',var1[5]) #截取到指定索引值

print('val[5]:',var1[1:5]) #指定范围值

var1= 'hellworld'

print('更新字符串:','welcome ' + var1[:9] ) #数字9代表变量的起始位置

相关文章

网友评论

      本文标题:shuffle()

      本文链接:https://www.haomeiwen.com/subject/urvoyftx.html