摘要: 函数是带名字的代码块,用于完成具体的工作 要执行函数定义的特定任务,可调用该函数。 什么时候使用函数: 当在程序中需要多次使用同一功能的时候,为了简化代码,可以把这个功能定义到函数。 定义一个最简单的函数 >>> def hi(): ... print("hello,world") >>> hi() 阅读全文
posted @ 2017-05-08 22:40 alben-xue 阅读(782) 评论(0) 推荐(0) 编辑
摘要: 1、在列表间移动元素 #!/usr/bin/env python #filename=list.py num1 = [1,3,5,7,9,11,13,15] num2 = [] while num1: interest_number = num1.pop() num2.append(interest 阅读全文
posted @ 2017-05-08 21:13 alben-xue 阅读(971) 评论(0) 推荐(0) 编辑
摘要: 函数input()的工作原理: 函数input()让程序短暂运行,等待用户输入一些文本,获取用户输入后将其存储在一个变量中 测试input()功能—— #!/usr/bin/env python#filename:input().py message=input("tell me something 阅读全文
posted @ 2017-05-08 00:15 alben-xue 阅读(685) 评论(0) 推荐(0) 编辑