# ----------------------------------------------------------------------
# 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-课堂代码的更多相关文章

  1. html语义化练习易牛课堂代码

    html <body>     <header>         <!-- 导航 -->         <nav> <a href=" ...

  2. 20155315 2017-05-10 《Java程序设计》课堂代码检查

    一.教材代码检查-p98 代码要求 修改教材P98 Score2.java, 让执行结果数组填充是自己的学号 代码链接 运行结果截图 二.在IDEA中以TDD的方式对String类和Arrays类进行 ...

  3. Struts2整理+课堂代码+注意事项

    1.在Struts配置文件的<package   中的 namespace默认是namesopace="/". 当生成namespace=“abc/”(abc是自己定义的,类 ...

  4. Android——数据存储(课堂代码整理:SharedPreferences存储和手机内部文件存储)

    layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  5. Ajax与Jquery题库

    一.    填空题 1.在JQuery中被誉为工厂函数的是 $() . 2.在jQuery中需要选取<div>元素里所有<a>元素的选择器是 $("div a&quo ...

  6. 【学习笔记】【C语言】变量

    1. 什么是变量 当一个数据的值需要经常改变或者不确定时,就应该用变量来表示.比如游戏积分. 2. 定义变量 1> 目的 任何变量在使用之前,必须先进行定义. 定义变量的目的是:在内存中分配一块 ...

  7. 韩顺平HTML5教程www.gis520.com

    传智播客.韩顺平.HTML5游戏公开课-坦克大战01.HTML5介绍.HTML5发展.HTML5学习网站推荐.wmv http://dl.vmall.com/c0b7xrkftf 传智播客.韩顺平.H ...

  8. 新闻公布系统 (Asp.net 三层架构 )

    2012年度课程设计---新闻公布系统(小结)                                                                             ...

  9. 01-UIKit

    目录: 一.视图和控制器 二.interface Builder 回到顶部 一.视图和控制器 1 视图(view)ios程序运行期间用户所能看见的东西都可以认为是视图,比如UIwindow就是一个视图 ...

  10. 32位汇编第四讲,干货分享,汇编注入的实现,以及快速定位调用API的数量(OD查看)

    32位汇编第四讲,干货分享,汇编注入的实现,以及快速定位调用API的数量(OD查看) 昨天,大家可能都看了代码了,不知道昨天有没有在汇编代码的基础上,实现注入计算器. 如果没有,今天则会讲解,不过建议 ...

随机推荐

  1. Mybatis中trim标签的用法

    select * from t_user <trim prefix="WHERE" prefixOverrides="and"> <if te ...

  2. mysql5.7.13.zip安装(windows)

    按照我之前安装5.6的安装方法(MySQL免安装版下载与配置)安装5.7的时候出现问题: mysql服务无法启动,服务没有报任何错误

  3. 消息推送SignalR简单实例

    消息推送SignalR:一个ASP .NET 下的类库,可以在ASP .NET 的Web项目中实现实时通信. 功能:当所连接的客户端变得可用时服务器代码可以立即向其推送内容,而不是让服务器等待客户端请 ...

  4. POJ1811(SummerTrainingDay04-G miller-rabin判断素性 && pollard-rho分解质因数)

    Prime Test Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 35528   Accepted: 9479 Case ...

  5. vue.js关于路由的跳转

    1.路由demo示例 <div id="app"> <h1>Hello App!</h1> <p> <!-- 使用 route ...

  6. 微信公众号获取acess_token并存储(php)

    <?php define("appid", "你的appid"); define("appsecret", "你的appse ...

  7. js-ES6学习笔记-对象的扩展

    1.ES6允许直接写入变量和函数,作为对象的属性和方法.这种写法用于函数的返回值,将会非常方便.CommonJS模块输出变量,就非常合适使用简洁写法. var ms = {}; function ge ...

  8. git基础使用——TortoiseGit

    一.初识git Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制 ...

  9. ionic1项目中 ion-slide轮播用ng-repeat遍历数据后自动循环出问题

    <ion-slide-box>属性中循环播放:dose-continue=‘true’,但是在项目遇到这样一个问题,从后台获取数据后将数据ng-repeat到<ion-slide&g ...

  10. JSP内置对象——application对象

    下面来举个具体的实例: 运行结果: 其中,city,postcode,email是我自己保存的属性名称,然后最后一行还获取到了当前JSP或者SERVLET的引擎名及版本号.