day4-课堂代码
# ----------------------------------------------------------------------
# def my_function1(name, address, age):
# print('姓名:%s, 地址:%s, 年龄:%s' % (name, address, age))
#
# # 正确:
# my_function1('北京',50,'田老师')
#
# # 错误:
# my_function1(50, '北京', '田老师')
#
# # 指定参数名,顺序可以与定义时不一致
# my_function1(age=50, address='北京', name='田老师') # 默认值 # 我们已知的情况:
# def my_function2(name, age):
# print('姓名:%s, 年龄:%s' % (name, age))
# #
# my_function2('田老师') # 一定场景下,带默认值
# def my_function2(name, age=18):
# print('姓名:%s, 年龄:%s' % (name, age))
# #
# my_function2('张老师')
# my_function2('田老师', 46) # 有默认值时的参数顺序
# 正确:
# def enroll(name, city='Beijing'):
#
# print('name:', name)
# print('city:', city)
# print('-------------') # def enroll(name, city='Beijing'):
#
# print('name:', name)
# print('city:', city)
# print('-------------')
# #
# enroll('ShangHai') # 以下的代码的输出什么? 你将如何修改 extendList 的定义所带来的隐患问题
# def extendList(val, list=[]):
# list.append(val)
# return list # def extendList(val, list=None):
# if list == None:
# list = []
# list.append(val)
# return list
#
# list1 = extendList(10) # list1 = [10]
# list2 = extendList(123, []) # list2 = [123]
# list3 = extendList('a') # list3 = ['a']
#
# print("list1 = %s" % list1)
# print("list2 = %s" % list2)
# print("list3 = %s" % list3) # 隐患和修改方法:
# 函数定义时,如果参数有默认值,则在定义时就会开辟一块内存空间来存储该默认值
# 调用函数时,如果未给有默认值的参数传值,就会使用该内存空间的数据
# 多次调用时,该空间就会被重复使用,如果某一次调用时改变了该空间的数据,其他次调用也会收到影响
# 可变数据类型,内存空间内容可以被改变,所以尽可能不用可变数据类型
# 如果一定要用,默认值不要用空对象,应该用None # 可变参数 *
# def my_function3(name, age, gender, *other):
# print('name:', name)
# print('age:', age)
# print('gender:', gender)
# print('other:', other)
#
# my_function3('田老师', 56, '男', '北京','慧测','汤立路220号','哈哈哈') # 可变参数 **
# def my_function4(name, age, gender, **other):
# print('name:', name)
# print('age:', age)
# print('gender:', gender)
# print('other:', other)
# #
# my_function4('田老师',56, '男', city='北京', corp='慧测', address='汤立路220号') # 参数顺序一般是非可选参数在前,可选参数在后 # 1 *
# def enroll(name, *other):
#
# print('name:', name)
# print('other:', other)
#
# enroll('zhanglaoshi', 18, '北京') # 这样也可以,但不建议
# def enroll(*other, name):
#
# print('name:', name)
# print('other:', other)
#
# enroll( 'Beijing', 18, name='张老师') # 2 **
# def enroll(name, **other):
# print('name:', name)
# print('other:', other) #
# # 调用时传参
# enroll(address='Beijing', age=18, name='张老师') # return
# def my_function4():
# print(1)
# return # def calc(x,y):
# a = x+y
# b = x-y
# c = x*y
#
# return a,b,c
#
# print(calc(3,4))
#
# def is_longer_than_5(seq):
# if len(seq)>5:
# return True
# else:
# return False
#
# print(is_longer_than_5('hello')) # def avg(list):
# sum = 0
# for ele in list:
# sum += ele
# length = len(list)
# return sum/length
#
# print(avg([1,2,5,7,8]))
#
# my_function4() # 3. (选做)编写一个生成get请求地址的函数,上游传递过来的参数有url=“”,domain=“”,data={},
# 请根据以上参数返回一个get请求的完整链接,其中data和url有可能不传
#
# http://127.0.0.1/access/log?a=1&b=2
# domain url data {'a':1,'b':2} # def gen_get_address(domain, url=None, data=None):
# address = 'http://' + domain
# if url:
# address += '/' + url
# if data:
# params_list = []
# for k, v in data.items():
# param = k + '=' + v
# params_list.append(param)
# params = '&'.join(params_list)
# address += '?' + params
# return address
#
#
# print(gen_get_address(domain='127.0.0.1',
# url='huice/huice',
# data={'usr': 'tiantian', 'passwd': 'bugaosuni'})) # 递归 # 5! = 5* 4!
# 4! = 4* 3!
#
# n! = n * (n-1)! # def fact(n):
# if n == 1:
# return 1
# return n * fact(n-1)
#
# print(fact(100)) # def factorial(n):
# if n > 1:
# return n * factorial(n - 1)
# elif n == 0 or n == 1:
# return 1
#
# print(factorial(100)) # a = 'hello'
# for i in map(ord, a):
# print(i)
#
# def my_func(x):
# return x + 'kitty' # m = map(lambda x: x + 'kitty', ['hello', 'haha', 'hei', 'hehe', 'helloworld'])
# print(list(m))
#
#
# def is_longer_than_3(seq):
# if len(seq) > 3:
# return True
# else:
# return False
#
#
# result = filter(is_longer_than_3, ['hello', 'haha', 'hei', 'hehe', 'helloworld'])
# print(list(result)) # filter
# def ispositive(x):
# if x>0:
# return True
# else:
# return False
#
# result = filter(ispositive, [1,-2,3,-1,4])
# print(list(result))
#
# a = ['adam', 'LISA', 'barT']
#
# def my_capitalize(string):
# return string.capitalize()
#
# print(list(map(my_capitalize, a))) class HuiceStudent:
'慧测学生类'
school = 'Huice'
__xuefei = 980 def __init__(self, xingming, nianling=18):
self.name = xingming
self.age = nianling def __study(self):
''
print(self.name +'交完'+ str(self.xuefei) + '在学习!') def eat(self, something):
print(self.name + '在吃' + something) @classmethod
def go_to_school(cls):
print('欢迎来' + cls.school) @staticmethod
def my_print():
print('haha'+ HuiceStudent.school) def __len__(self):
return len(self.name) def __str__(self):
return '%d岁的学生%s' % (self.age, self.name) @classmethod
def get_xuefei(cls):
# if authority = 'boss':
return cls.__xuefei
# else:
# return None
@classmethod
def set_xuefei(cls, new_xuefei):
if new_xuefei > 1000 or new_xuefei < 900:
print('学费不合理')
else:
cls.__xuefei = new_xuefei
print('设置成功') # 学校
# 学费 类变量
#
# 姓名
# 身高 实例变量 成员变量
#
# 上学 类方法
#
# 跑
# 跳
# 吃
# 学习 成员方法
#
#
#
# pass # a = HuiceStudent('张三')
# b = HuiceStudent('李四')
# print(a.name)
# print(a.xuefei)
# a.xuefei = 930
# print('李四的学费是', b.xuefei)
# b.study()
# b.eat('肉')
# b.go_to_school()
#
# # print(HuiceStudent.xuefei)
#
# HuiceStudent.go_to_school() # print(HuiceStudent._HuiceStudent__xuefei) # print(HuiceStudent.__doc__) # c = HuiceStudent('王五')
# print(c.name)
# c.eat('肉肉')
# print(len(c))
# print(c)
#
#
# print(HuiceStudent.get_xuefei())
#
# HuiceStudent.set_xuefei(990)
# print(HuiceStudent.get_xuefei())
# # class Stack:
# def __init__(self, max_size):
# __lst = []
# self.max_size = max_size
#
# def pop(self):
# pass
#
# def push(self, element):
# pass
#
# def get # class Auto:
# def __init__(self, pinpai, yanse):
# self.brand = pinpai
# self.speed = 0
# self.color = yanse
#
# def start(self):
# print self.brand + '启动了'
#
# def speedup(self):
# self.speed += 10
#
# def stop(self):
# if self.speed > 30:
# self.speed -= 30
# else:
# self.speed = 0
#
#
# if __name__ == '__main__':
#
# mycar = Auto('BMW', '蓝色')
# mycar.start()
# mycar.speedup()
# mycar.speedup()
# mycar.speedup()
# mycar.speedup()
# mycar.speedup()
# print mycar.speed
# mycar.stop()
# print mycar.speed
# mycar.stop()
# print mycar.speed # class Animal:
# def __init__(self, name):
# self.name = name
#
# def eat(self):
# print(self.name + '在吃东西')
#
# def run(self):
# print(self.name + 'is running!')
#
#
# # ani = Animal('动物')
# # ani.eat()
# # ani.run()
#
# class Dog(Animal):
#
# def bark(self):
# print(self.name + '在狂吠')
#
# def eat(self):
# print(self.name + '在吃骨头')
#
# class Cat(Animal):
#
# def eat(self):
# print(self.name + '在吃<・)))><<')
#
# class Tiger(Animal):
#
# def eat(self):
# print(self.name + '在吃肉')
#
# class Elephant(Animal):
#
# def eat(self):
# print(self.name + '在吃树叶')
# # class Person:
# def __init__(self, name):
# self.name = name
#
# def feed(self, a):
# a.eat() # def feed_cat(self, cat):
# cat.eat()
#
# def feed_tiger(self, tiger):
# tiger.eat() # t = Person('tiantian')
# d = Dog('旺旺')
# c = Cat('花花')
# tg = Tiger('大王')
# e = Elephant('大白')
#
# t.feed(d)
# t.feed(c)
# t.feed(tg)
# t.feed(e)
#
# def bark(self):
# print('汪汪')
#
# def eat(self):
# print(self.name, '在吃骨头')
#
# class Cat(Animal):
#
# def eat(self):
# print(self.name, '在吃鱼')
#
# class Tiger(Animal):
#
# def eat(self):
# print(self.name, '在吃肉')
#
# class Elephant(Animal):
#
# def eat(self):
# print(self.name, '在吃树叶')
#
# class Person:
# def __init__(self,name):
# self.name = name
#
# # def feed_dog(self, dog):
# # dog.eat()
# #
# # def feed_cat(self, cat):
# # cat.eat()
# #
# # def feed_tiger(self, tiger):
# # tiger.eat()
#
# def feed(self, anim):
# anim.eat()
#
#
# tls = Person('tianlaoshi')
# #
# mydog = Dog('旺旺')
# mycat = Cat('花花')
# mytiger = Tiger('大王')
# myele = Elephant('小白')
#
# # tls.feed_cat(mycat)
# # tls.feed_dog(mydog)
# # tls.feed_tiger(mytiger)
# #
# tls.feed(mydog)
# tls.feed(mycat)
# tls.feed(mytiger)
# tls.feed(myele)
#
# #多态 #异常 # import sys
# import traceback
# ImportError:导入模块错误
# import A # IndexError:索引超出范围
# list1 = [1,2,3]
# print(list1[3]) # KeyError:字典中不存在的键
# dict1 = {'name':'ivy','age':20,'gender':'female'}
# print(dict1['height']) # NameError:访问没有定义的变量
# print(a) # IndentationError:缩进错误
# if 1==1:
# print 'aaa' # SyntaxError:语法错误
# list2 = [1,2,3,4 # TypeError:不同类型间的无效操作
# print(1+'1') # ZeroDivisionError:除数为0
# print(a/b)
# try:
# print(5/0)
#
# print('hehe')
# except:
# print('haha')
# raise BaseException('除数不能为0')
# # finally:
# # print('xixi')
#
# print('haha') # import traceback
# #捕获 抓
# def sum(a,b):
# try:
# return a/b
# except (ZeroDivisionError, TypeError) as e:
# traceback.print_exc()
# print e
# return 0
#
# print sum(5, 'a')
# print 'haha' # 无法预知的调用错误
# def sum(a, b):
# print a+b
#
# print sum(0, 1)+2 # print long(a) # raise ZeroDivisionError('除数不能为0') # def test():
# try:
# print 5/0
# print 1
# except (TypeError, ZeroDivisionError):
# print 'error'
# return 0
# finally:
# print '0000'
#
# print test() # a = [1,'a','c',10,23]
#
# counter = 0
# for ele in a:
# try:
# int(ele)
# except:
# counter += 1
# print counter # try:
# print 'try...'
# r = 10 / 0
# print 'result:', r
# except ZeroDivisionError, e:
# print 'except:', e
# finally:
# print 'finally...'
# print 'END'
#
# try:
# print 'try...'
# r = 10 / int('a')
# print 'result:', r
# except ValueError, e:
# print 'ValueError:', e
# except ZeroDivisionError, e:
# print 'ZeroDivisionError:', e
# finally:
# print 'finally...'
# print 'END' import day3
from Day4 import file1
# from Day4.file1 import HuiceStudent
# HuiceStudent() import time
print(time.strftime('%Y%m%d%H%M%S', time.localtime())) import random
for i in range(1, 11):
a = random.randint(1,100)
print(a)
day4-课堂代码的更多相关文章
- html语义化练习易牛课堂代码
html <body> <header> <!-- 导航 --> <nav> <a href=" ...
- 20155315 2017-05-10 《Java程序设计》课堂代码检查
一.教材代码检查-p98 代码要求 修改教材P98 Score2.java, 让执行结果数组填充是自己的学号 代码链接 运行结果截图 二.在IDEA中以TDD的方式对String类和Arrays类进行 ...
- Struts2整理+课堂代码+注意事项
1.在Struts配置文件的<package 中的 namespace默认是namesopace="/". 当生成namespace=“abc/”(abc是自己定义的,类 ...
- Android——数据存储(课堂代码整理:SharedPreferences存储和手机内部文件存储)
layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- Ajax与Jquery题库
一. 填空题 1.在JQuery中被誉为工厂函数的是 $() . 2.在jQuery中需要选取<div>元素里所有<a>元素的选择器是 $("div a&quo ...
- 【学习笔记】【C语言】变量
1. 什么是变量 当一个数据的值需要经常改变或者不确定时,就应该用变量来表示.比如游戏积分. 2. 定义变量 1> 目的 任何变量在使用之前,必须先进行定义. 定义变量的目的是:在内存中分配一块 ...
- 韩顺平HTML5教程www.gis520.com
传智播客.韩顺平.HTML5游戏公开课-坦克大战01.HTML5介绍.HTML5发展.HTML5学习网站推荐.wmv http://dl.vmall.com/c0b7xrkftf 传智播客.韩顺平.H ...
- 新闻公布系统 (Asp.net 三层架构 )
2012年度课程设计---新闻公布系统(小结) ...
- 01-UIKit
目录: 一.视图和控制器 二.interface Builder 回到顶部 一.视图和控制器 1 视图(view)ios程序运行期间用户所能看见的东西都可以认为是视图,比如UIwindow就是一个视图 ...
- 32位汇编第四讲,干货分享,汇编注入的实现,以及快速定位调用API的数量(OD查看)
32位汇编第四讲,干货分享,汇编注入的实现,以及快速定位调用API的数量(OD查看) 昨天,大家可能都看了代码了,不知道昨天有没有在汇编代码的基础上,实现注入计算器. 如果没有,今天则会讲解,不过建议 ...
随机推荐
- IDEA@Data注释使用
@Data注解主要是帮助解决Setter 和 Getter以及 toString这种重复的无脑工作 加入@Data注解可以直接帮助我们添加实体类相应的Setter 和 Getter以及 toStrin ...
- Java JDBC的基础知识(一)
一.为什么引入JDBC 在学习JDBC之前,抛开它的概念,我先按照我的理解解释一下,为什么要引入JDBC.在我看来,引入JDBC跟我之前学过的引入JVM(Java虚拟机)有些相似之处.当然,关于JVM ...
- 大明A+B(hdu1753)大数,java
大明A+B Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- deferred对象详解
什么是Deferred对象 defer,推迟:延期.含义就是”延迟”到未来某个点再执行. 在开发中,我们经常遇到某些耗时很长的javascript操作.其中,既有异步的操作(比如ajax读取服务器数 ...
- cf19E. Fairy(奇环 二分图染色)
题意 题目链接 Sol 非常有思维含量的一道题,队爷的论文里介绍了一种\(N \sqrt{N}\)的暴力然鹅看不懂.. 看了一下clj的\(O(nlogn)\)的题解,又翻了翻题交记录,发现\(O(n ...
- 1.String、StringBuffer与StringBuilder之间区别
1.三者在执行速度方面的比较:StringBuilder > StringBuffer > String 2.String <(StringBuffer,StringBuild ...
- 【读书笔记】iOS-网络-底层网络
在iOS上,有一个库叫做Core Foundation networking或CFNetwork,它是对原始Socket的轻量级封装,不过它很快对于大多数常见场景来说变得非常笨重了.最后,添加了另一层 ...
- SpringMVC—Struts2拦截器学习网址整理
引自:http://blog.csdn.net/wp1603710463/article/details/49982683 SpringMVC—Struts2拦截器学习网址整理 最近项目中遇到权限相关 ...
- 高德地图 JS API - 根据地名实现标记定位
德地图 JS API 使用前的准备工作请参考官方网站说明: https://lbs.amap.com/api/javascript-api/guide/abc/prepare 根据地名实现地图标记定位 ...
- [原创]数据驱动决策:BI在零售业的数据化管理
无论是商业智能时代的应用建设,还是当下大数据时代的数据应用/数据产品建设,行业化.角色化与场景化,均是一个重要的趋势. 当下,许多企业逐步开始具备场景化思维,更为注重用户体验,业务运营更多的围绕用户的 ...