PYTHON

Posted Carzy_Learner

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PYTHON相关的知识,希望对你有一定的参考价值。

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

 

 

以上是关于PYTHON的主要内容,如果未能解决你的问题,请参考以下文章

PythonPython库之机器学习

PythonPython库之机器学习

PythonPython库之游戏开发

PythonPython库之游戏开发

PythonPython XML 读写

PythonPython库之Web信息提取