博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PYTHON常见数据类型示例
阅读量:4614 次
发布时间:2019-06-09

本文共 2141 字,大约阅读时间需要 7 分钟。

shoplist = ['apple', 'mango', 'carrot', 'banana']print('I have ', len(shoplist), ' items to purchase.')print('These items are: ', end = '')for  item in shoplist:    print(item, end = ' ')print('\nI also have to buy rice.')shoplist.append('rice')print('My shopping list is now ', shoplist)print('I will sort my list now')shoplist.sort()print('Sorted shopping list is ', shoplist)print('The first item I will buy is ', shoplist[0])olditem = shoplist[0]del shoplist[0]print('I bought the ', olditem)print('My shopping list is now ', shoplist)zoo = ('python', 'elephant', 'penguin')print('Number of animals in the zoo is ', len(zoo))new_zoo = 'monkey', 'camel', zooprint('Number of cages in the new zoo is ', len(new_zoo))print('All animals in new zoo are ',new_zoo)print('Animals brought from old zoo are', new_zoo[2])print('Last animal brought from old zoo is ', new_zoo[2][2])print('Number of animals in the new zoo is ', len(new_zoo) - 1 + len(new_zoo[2]))ab = {  'Swaroop'    : 'Swaroop@Swaroopch.com',        'Larry'        : 'larry@wall.org',        'Matsumoto'    : 'matz@ruby-lang.org',        'Spammer'    : 'spammer@hotmail.com'}print("Swaroop's address is ", ab['Swaroop'])del ab['Spammer']print('\nThere are {0} contacts in the address-book\n'.format(len(ab)))for name, address in ab.items():    print('Contatc {0} at {1}'.format(name, address))ab['Guido'] = 'guido@python.org'if 'Guido' in ab:    print("\nGuido's address is ", ab['Guido'])name = 'Swaroop'print('Item 0 is ', shoplist[0])print('Item 1 is ', shoplist[1])print('Item 2 is ', shoplist[2])print('Item 3 is ', shoplist[3])print('Item -1 is ', shoplist[-1])print('Item -2 is ', shoplist[-2])print('Character 0 is ', name[0])print('Item 1 to 3 is ',shoplist[1:3])print('Item 2 to end is ',shoplist[2:])print('Item 1 to -1 is ',shoplist[1:-1])print('Item start to end is ',shoplist[:])print('Character 1 to 3 is ', name[1:3])print('Character 2 to end is ', name[2:])print('Character 1 to -1 is ', name[1:-1])print('Character start to end is ', name[:])bri = set(['brazil', 'russia', 'India', 'China'])print('India' in bri)

转载于:https://www.cnblogs.com/aguncn/p/3242533.html

你可能感兴趣的文章
队列实现霍夫曼树
查看>>
关于微信公众平台测试号配置失败的问题
查看>>
【NOIP2001】统计单词个数
查看>>
linux常用端口
查看>>
异常处理
查看>>
/proc/uptime详解
查看>>
如何建立合适的索引?
查看>>
acwing 651. 逛画展
查看>>
Vijos P1243 生产产品 (单调队列优化DP)
查看>>
iOS常用第三方库 -转
查看>>
Android布局学习
查看>>
jQuery中事件绑定与解绑
查看>>
js原生Ajax的封装与使用
查看>>
周总结6
查看>>
PostgreSQL 务实应用(二/5)插入冲突
查看>>
一种公众号回复关键词机制
查看>>
java多线程入门学习(一)
查看>>
基于 Web 的 Go 语言 IDE - Wide 1.1.0 公布!
查看>>
nyist oj 138 找球号(二)(hash 表+位运算)
查看>>
Movidius软件手册阅读 2017-09-04
查看>>