博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PYTHON
阅读量:4567 次
发布时间:2019-06-08

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

1.元组的概念和用法

zoo = ('wolf','elephant','penguin')

print ('Number of animals in the zoo is',len(zoo))

new_zoo = ('monkey','dolphin',zoo)

print ('Number of animals 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])

2.百分号取元组数据

age = 22

name = 'Swaroop'

print ('%s is %d years old'%(name,age))

print ('Why is %s playing with that python?' % name)

3.字典的用法

ab = { 'Swaroop' :'Swaroopch@byteofpython.info',

'Larry' :'Larry@wall.org',
'Matsumoto' :'matz@ruby-lang.org',
'Spammer' :'spammer@hotmail.com'
}
print ("Swaroop's address is %s" %ab['Swaroop'])

4.列表用法

shoplist = ['apple' , 'mango' , 'carrot' , 'banana']

print ('Item 0 is ' , shoplist[0])
print ('Item 3 is ' , shoplist[3])
print ('Item -1 is ' , shoplist [-1])

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 [:])

name = 'swaroop'

print ('characters 1 to 3 is ' , name[1:3])
print ('characters 2 to end is ',name[2:])
print ('characters 1 to -1 is ' , name[1:-1])
print ('characters start to end is',name[:])

 

 

转载于:https://www.cnblogs.com/dadaozhijian22/p/7868009.html

你可能感兴趣的文章
高可用集群搭建
查看>>
Lua学习笔记
查看>>
Redis监控工具,命令和调优
查看>>
zabbix-mysql迁移分离
查看>>
jQuery调用WCF 说明
查看>>
算法第5章作业
查看>>
7.9 练习
查看>>
基于ArcGIS JS API的在线专题地图实现
查看>>
learnByWork
查看>>
lua 函数
查看>>
Git的基本命令
查看>>
四平方和
查看>>
第十八周 12.27-1.2
查看>>
C# IP地址字符串和数值转换
查看>>
TCHAR和CHAR类型的互转
查看>>
常用界面布局
查看>>
C语言—— for 循环
查看>>
IBM lotus9.0测试版即将公测
查看>>
xml常用方法
查看>>
Cube Stacking(并差集深度+结点个数)
查看>>