上一页 1 ··· 3 4 5 6 7 8 下一页
摘要: 函数是带名字的代码块,用于完成具体的工作 要执行函数定义的特定任务,可调用该函数。 什么时候使用函数: 当在程序中需要多次使用同一功能的时候,为了简化代码,可以把这个功能定义到函数。 定义一个最简单的函数 >>> 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) 编辑
摘要: 套嵌 把字典储存在列表中或将列表作为值存储在字典中,这种方式称为套嵌! 1、字典列表 使用列表来包含不同类型的alien(同时每个alien类型对应一个字典) 第一步:创建字典 >>> alien_0={'color':'green','points':5}>>> alien_1={'color': 阅读全文
posted @ 2017-05-06 22:25 alben-xue 阅读(216) 评论(0) 推荐(0) 编辑
摘要: #在Python中,字典是一系列(键-值)对。每一个键都与一个值相关联, 可以使用键来访问与之相关联的值# 值:键对应的值可以是如下类型 1、数字 2、字符串 3、列表 4、字典 定义一个简单的字典: >>> alien_0={'color':'green','point':5}>>> type(a 阅读全文
posted @ 2017-05-05 16:47 alben-xue 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 1、遍历整个列表 #for 循环 # >>> name_list['faker', 'dopa', 'gogoing', 'uzi'] >>> for LOL_Player in name_list:... print(LOL_Player)fakerdopagogoinguzi 第一步,定义一个列 阅读全文
posted @ 2017-05-04 22:54 alben-xue 阅读(346) 评论(0) 推荐(0) 编辑
摘要: Python的文件操作: 打开文件;open函数 open的方式有三种 1,r(read-only)也是python中默认的文件打开模式 2,w(write-only)只写模式,比较危险,会覆盖当前文件内容 3,a(append)追加模式,对文件追加内容 读取文件: 读取的方式有三种 read() 阅读全文
posted @ 2017-05-03 15:33 alben-xue 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 预设文件: 黑名单 —— lockuser 用户数据库 —— userlist 密码数据库 —— passwd 代码段: #!/usr/bin/env pythonimport sysa=open('lockusers','r')blacklist=a.read()a.close()blacklis 阅读全文
posted @ 2017-05-03 15:32 alben-xue 阅读(363) 评论(0) 推荐(0) 编辑
摘要: 字符串就是一系列字符。在python中,用引号括起来的都是字符串,这里的引号可以是单引号也可以双引号。 例如: >>> 'this is a string' 'this is a string'>>> “this is also a string”“this is also a string” 对字 阅读全文
posted @ 2017-05-03 15:31 alben-xue 阅读(220) 评论(0) 推荐(0) 编辑
摘要: 列表由一系列特定顺序排列的元素组成,在python中使用[]来表示列表,并用,来进行元素分割。 >>> name_list['alben', 'james', 'harden', 'faker'] 列表的索引(index) 在python中,列表的index从0开始,可以通过index来指定访问哪个 阅读全文
posted @ 2017-05-03 15:29 alben-xue 阅读(263) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 下一页