博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[简明python教程]学习笔记2014-04-29 23:41:40
阅读量:6348 次
发布时间:2019-06-22

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

学习内容:

1.学习了模块,包括制作自己的模块

2.学习了数据结构的列表、元组

[root@reed 0429]# for i in $(ls *.py);do echo "cat $i";cat $i;echo; donecat mymodule_dem2.py#!/usr/bin/pythonfrom mymodule import sayhi,version,datesayhi()print versionprint datecat mymodule_dem.py#!/usr/bin/pythonimport mymodulemymodule.sayhi()print 'version is',mymodule.versionprint 'date is ',mymodule.datecat mymodule.py#!/usr/bin/pythondef sayhi():        print 'hello,this is my module speaking'version='1.0'date='20140429'cat print_tuple.py#!/usr/bin/pythonage=27name='reed'print '%s is %d years old'%(name,age)cat using_list.py#!/usr/bin/pythonshoplist=['apple','mango','carrot','banana']print 'i have',len(shoplist),'items to purchase.'print 'these items are:',for item in shoplist:        print item,print '\ni alse have to buy rice.'shoplist.append('rice')print 'my shopping list is now',shoplistprint 'i will sort my list'shoplist.sort()print 'sorted shopping list is',shoplistprint 'the first item i will buy is',shoplist[0]olditem=shoplist[0]del shoplist[0]print 'i bought the',olditemprint 'my shopping list is now',shoplistcat using_name.py#!/usr/bin/pythonif __name__=='__main__':        print 'this program is beging run by itself'else:        print 'i am being imported from another module'cat using_sys.py#!/usr/bin/pythonimport sysprint 'the command line arguments are:'for i in sys.argv:        print iprint '\n\nThe PYTHON PATH is',sys.path,'\n'cat using_tuple.py#!/usr/bin/pythonzoo=('wolf','elephant','penguin')print 'number of animals in the zoo is',len(zoo)new_zoo=('monkey','dolphin',zoo)print 'number of animals in the zoo is',len(new_zoo)print 'all animals in new zoo are',new_zooprint 'animals brought from old zoo are',new_zoo[2]print 'animals brought from old zoo is',new_zoo[2][2]

转载地址:http://kapla.baihongyu.com/

你可能感兴趣的文章
iOS开发笔记--iOS后台发送邮件
查看>>
mac下使用ssh
查看>>
创建与删除SQL约束或字段约束
查看>>
topshelf和quartz内部分享
查看>>
讲义(2)
查看>>
【转载】SQL Server 2008-建立分区表(Table Partition)
查看>>
Linux --常见Linux目录名称
查看>>
ThinkPHP import 使用及问题
查看>>
VLV INDEX
查看>>
iosOpenDev-install 失败官方wiki无法解决看这里(尝试有效)
查看>>
UEditor 中配置可以跨域访问的图片路径
查看>>
记一次权限分配的问题
查看>>
aspnet网页刷新
查看>>
魔兽世界客户端数据研究(二)
查看>>
在一台机子上面安装SQL Server 2000 + 2005 + 2008
查看>>
2257: [Jsoi2009]瓶子和燃料
查看>>
double? int?
查看>>
java抽象类和接口
查看>>
3D动画
查看>>
Sencha-组件-Chart(图表)(官网文档翻译17)
查看>>