码迷,mamicode.com
首页 > 编程语言 > 详细

Python的取值

时间:2021-01-14 11:35:28      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:day   获取   print   一个   nihao   mon   list   one   and   

list1 =[1, 2, 3, 4, 5, 6]
list2 =[‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ]
list3 =[1, 3, ‘a‘, ‘c‘, True]
print(list1)
print(‘使用切片方式获取指定list1第三个元素:%d‘ % list1[3])
print(‘获取最后一个元素:%d‘ % list1[-1])
print(‘获取第一个元素:%s‘ % list1[:1])
print(‘获取第2到3的元素:%s‘ % list1[1:3])
print(‘获取倒数第三道1:%s‘ % list1[3:1])
list1.append(2)
# 用1,2,3,4分别组成三位数
num = 0
for a in range(1, 5):
for b in range(1, 5):
for c in range(1, 5):
if a == b or a == c or c == b:
continue
print("{}{}{}".format(a, b, c))
num += 1

s = [‘nihao‘, ‘woshi‘, ‘???‘]
s.append(‘pi‘)
print(s)
s = [‘nihao‘, ‘woshi‘, ‘???‘]
s.insert(2, ‘nidaye‘)
print(s)
s = [‘nihao‘, ‘woshi‘, ‘???‘]
s.extend(‘wodelaojiaaaa‘)
print(s)
s = [‘nihao‘, ‘woshi‘, ‘???‘]
s.pop(0)
print(s)
s = [‘nihao‘, ‘woshi‘, ‘???‘]
s.remove(‘woshi‘)
print(s)
s = [‘nihao‘, ‘woshi‘, ‘???‘]
s.clear()
print(s)
s = [‘nihao‘, ‘woshi‘, ‘???‘]
del[s]
s = [‘nihao‘, ‘woshi‘, ‘???‘]
del s[0:2]
print(s)
s = [‘nihao‘, ‘woshi‘, ‘???‘]
s[1] = ‘nihao‘
print(s)
li = [1, 2, 3, 4, 5, ‘money‘, 2, 2, 3, 4, 5, ‘nihaoa‘]
li[1] = ‘aaaa‘
print(li)
li = [1, 2, 3, 4, 5, ‘money‘, 2, 2, 3, 4, 5, ‘nihaoa‘]
li[0:2] = ‘a‘
print(li)
names = [‘de‘, ‘ma‘, ‘xi‘, ‘ya‘]
print(names[2])
names = [‘mike‘, ‘mark‘, ‘candice‘, ‘laular‘]
print(names[1:3])
print(names[2:])
print(names[:3])
print(names[:])
print(names[-1])
print(names[1:3])

Python的取值

标签:day   获取   print   一个   nihao   mon   list   one   and   

原文地址:https://www.cnblogs.com/zxpnb/p/14275420.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!