摘要: """ """ __author__ = 'shaozhiqi' # 绑定属性时,如果我们直接把属性暴露出去,虽然写起来很简单, # 但是,没办法检查参数,导致可以把参数随便改 # 比如想限制student score的范围 class Student(object): def get_score(self): return self._score d... 阅读全文
posted @ 2019-09-19 16:14 ~清风煮酒~ 阅读(227) 评论(0) 推荐(0) 编辑
摘要: """ """ __author__ = 'shaozhiqi' # python是动态语言,所以定义类后,我们可以动态的给类绑定属性和方法,上一节都都与接触 class Student(object): pass s = Student() s.name = 'shaozhiqi' print(s.name) # shaozhiqi # 定义一个方法,绑定到s对象上,不会影响别的实例 def s 阅读全文
posted @ 2019-09-19 16:13 ~清风煮酒~ 阅读(231) 评论(0) 推荐(0) 编辑
摘要: """ """ __author__ = 'shaozhiqi' # 如何知道这个对象是什么类型,使用type() print(type(123)) # <class 'int'> print(type('abc')) # <class 'str'> print(type(None)) # <class 'NoneType'> print(type(abs)) # <class 'builtin_ 阅读全文
posted @ 2019-09-19 16:12 ~清风煮酒~ 阅读(367) 评论(0) 推荐(0) 编辑
摘要: """ 继承的多态 """ __author__ = 'shaozhiqi' # 父类 class Animal(object): def run(self): print('Animal is running...') # 子类 class Dog(Animal): pass # 子类 class Cat(Animal): pass # 子类实例 dog = Dog() dog.run() # 阅读全文
posted @ 2019-09-19 16:11 ~清风煮酒~ 阅读(216) 评论(0) 推荐(0) 编辑
摘要: """ 类和实例和访问权限 """ __author__ = 'shaozhiqi' # class后面紧接着是类名,即Student,类名通常是大写开头的单词, # 紧接着是(object),表示该类是从哪个类继承下来的 class Student(object): pass bart = Student() # 变量bart指向的就是一个Student的实例 bart.name = 'Bart 阅读全文
posted @ 2019-09-19 16:09 ~清风煮酒~ 阅读(296) 评论(0) 推荐(0) 编辑
摘要: """ 面向对象编程 """ __author__ = 'shaozhiqi' # 面向对象的程序设计把计算机程序视为一组对象的集合,而每个对象都可以接收其他对象发过来的消息,并处理这些消息,计算机程序的执行就是一系列消息在各个对象之间传递。 # 在Python中,所有数据类型都可以视为对象,当然也可以自定义对象 # 打印学生成绩,首先必须创建出这个学生对应的对象,然后,给对象发一个print_s 阅读全文
posted @ 2019-09-19 16:08 ~清风煮酒~ 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 先确保安装了windows的Python的pip 出现上图说明安装了,命令未找到则没有安装 安装一个图形处理的第三方库 Anaconda安装第三方库 我们经常需要用到很多第三方库,如MySQL驱动程序,Web框架等。用pip一个一个安装费时费力,还需要考虑兼容性。我们推荐直接使用Anaconda,这 阅读全文
posted @ 2019-09-19 16:07 ~清风煮酒~ 阅读(251) 评论(0) 推荐(0) 编辑
摘要: # 在Python中,一个.py文件就称之为一个模块(Module) # 1.最大的好处是大大提高了代码的可维护性。 # 2.可以被其他地方引用 # 3.python内置的模块和来自第三方的模块 # 4.使用模块还可以避免函数名和变量名冲突 # 5.同样,Python也有包(Package),同名不同包引用是也不会冲突。 # 每一个包目录下面都会有一个__init__.py的文件,这个文件是必须存 阅读全文
posted @ 2019-09-18 17:05 ~清风煮酒~ 阅读(442) 评论(0) 推荐(0) 编辑
摘要: # 偏函数(Partial function) # 如int()函数可以把字符串转换为整数,当仅传入字符串时,int()函数默认按十进制转换 print(int('12345')) # 12345 # 但int()函数还提供额外的base参数,默认值为10。如果传入base参数,就可以做N进制的转换: print(int('12345', base=8)) # 5349 print(int(... 阅读全文
posted @ 2019-09-18 17:03 ~清风煮酒~ 阅读(419) 评论(0) 推荐(1) 编辑
摘要: # -----------------------1-------------------------------------------- # 由于函数也是一个对象,而且函数对象可以被赋值给变量,所以,通过变量也能调用该函数。 def now(): print('2019-3-25') f = now print(f()) # 2019-3-25 print(now.__name... 阅读全文
posted @ 2019-09-18 17:01 ~清风煮酒~ 阅读(725) 评论(1) 推荐(1) 编辑
摘要: L = list(map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9])) print(L) # [1, 4, 9, 16, 25, 36, 49, 64, 81] # lambda x: x * x等价于下面的 def f(x): return x * x # 关键字lambda表示匿名函数,冒号前面的x表示函数参数。 # 匿名函数有个限制,就是只能有 阅读全文
posted @ 2019-09-18 16:59 ~清风煮酒~ 阅读(164) 评论(0) 推荐(0) 编辑
摘要: # 通常求和函数定义,调动就求和 def calc_sum(*args): ax = 0 for n in args: ax = ax + n return ax # 如果不需要立即求和 def lazy_sum(*args): def sum(): ax = 0 for n in args: ax = ax + n return ax return sum f = lazy_sum(1, 3, 阅读全文
posted @ 2019-09-18 16:58 ~清风煮酒~ 阅读(292) 评论(0) 推荐(0) 编辑
摘要: # 和map()类似,filter()也接收一个函数和一个序列。 # 和map()不同的是,filter()把传入的函数依次作用于每个元素, # 然后根据返回值是True还是False决定保留还是丢弃该元素。 def is_odd(n): return n % 2 == 1 # filter()函数返回的是一个Iterator,也就是一个惰性序列, # 所以要强迫filter()完成计算结果,需要 阅读全文
posted @ 2019-09-18 16:56 ~清风煮酒~ 阅读(218) 评论(0) 推荐(0) 编辑
摘要: # sorted()函数list进行排序: L = sorted([36, 5, -12, 9, -21]) print(L) # [-21, -12, 5, 9, 36] # 可以看到默认是按照升序排 LL = sorted([36, 5, -12, 9, -21], key=abs) print(LL) # [5, 9, -12, -21, 36] 自定义key 按照绝对值进行排序 lstr 阅读全文
posted @ 2019-09-18 16:56 ~清风煮酒~ 阅读(183) 评论(0) 推荐(0) 编辑
摘要: # map()函数接收两个参数,一个是函数,一个是Iterable, # map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回。 def f(x): return x * x r = map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9]) # f作用掉序列的每个元素上,可提高代码可读性 print(r) # <map object at 0x000000 阅读全文
posted @ 2019-09-18 16:54 ~清风煮酒~ 阅读(139) 评论(0) 推荐(0) 编辑
摘要: # 函数式编程的一个特点就是,允许把函数本身作为参数传入另一个函数,还允许返回一个函数! # 变量可以指向函数 abs(-10) # 10 abs # # ------abs(-10)是函数调用,而abs是函数本身 x = abs(-10) print(x) # 10 # 函数名也是变量 f = abs print(f) # print(f(-10)) # 10 # 说明变量... 阅读全文
posted @ 2019-09-18 16:53 ~清风煮酒~ 阅读(611) 评论(0) 推荐(0) 编辑
摘要: # 只要把一个列表生成式的[]改成() L = [x * x for x in range(10)] print(L) # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] g = (x * x for x in range(10)) print(g) # at 0x00000000021789C8> # print(next(g)) # 0 # print(ne... 阅读全文
posted @ 2019-09-18 16:52 ~清风煮酒~ 阅读(530) 评论(0) 推荐(0) 编辑
摘要: d = {'a': 1, 'b': 2, 'c': 3} for key in d: print(key, end=' ') # a b c dict的存储不是按照list的方式顺序排列,所以,迭代出的结果顺序很可能不一样 for ch in 'ABC': print(ch, end=' ') # A B C # 判断一个对象是否可迭代 from collections imp... 阅读全文
posted @ 2019-09-18 16:51 ~清风煮酒~ 阅读(312) 评论(0) 推荐(0) 编辑
摘要: # list或tuple的部分元素 L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack'] # 传统方法 print([L[0], L[1], L[2]]) # 取前三个值 r = [] n = 3 for i in range(n): r.append(L[i]) # 取前n个值 # 切片方法 # 从索引0开始取,直到索引3为止,但不包括索引3 prin 阅读全文
posted @ 2019-09-18 16:49 ~清风煮酒~ 阅读(1089) 评论(0) 推荐(0) 编辑
摘要: # Python 常用内置函数 https://docs.python.org/3/library/functions.html#abs print(help(abs)) # Return the absolute value of the argument. 返回参数的绝对值。 print(abs(-20)) # 20 print(max(2, 3, 1, -5)) # 3 # 类型转换 pri 阅读全文
posted @ 2019-09-18 16:47 ~清风煮酒~ 阅读(502) 评论(0) 推荐(0) 编辑
摘要: list create 阅读全文
posted @ 2019-09-18 16:46 ~清风煮酒~ 阅读(918) 评论(0) 推荐(0) 编辑
摘要: # Python的循环有两种,一种是for...in循环,依次把list或tuple中的每个元素迭代出来 names = ['Michael', 'Bob', 'Tracy'] for name in names: print(name) # 计算1-10的整数之和 sumAdd = 0 for x 阅读全文
posted @ 2019-09-18 16:45 ~清风煮酒~ 阅读(270) 评论(0) 推荐(0) 编辑
摘要: age = 20 if age >= 18: print('your age is', age) print('adult') # 如果if语句判断是True,就把缩进的两行print语句执行了,否则,什么也不做。 # else else: age = 3 if age >= 18: print(' 阅读全文
posted @ 2019-09-18 16:44 ~清风煮酒~ 阅读(375) 评论(0) 推荐(0) 编辑
摘要: # !/usr/bin/env python3 # -*- coding: utf-8 -*- # list是一种有序的集合,可以随时添加和删除其中的元素。 classmates = ['Michael', 'Bob', 'Tracy'] print(classmates) # ['Michael', 'Bob', 'Tracy'] print(len(classmates)) # 3 pr... 阅读全文
posted @ 2019-09-18 16:43 ~清风煮酒~ 阅读(247) 评论(0) 推荐(0) 编辑
摘要: # ASCII编码和Unicode编码的区别:ASCII编码是1个字节,而Unicode编码通常是2个字节。 # Unicode把所有语言都统一到一套编码里,这样就不会再有乱码问题了。 # 新的问题又出现了:如果统一成Unicode编码,乱码问题从此消失了。但是,如果你写的文本基本上全部是英文的话,用Unicode编码比ASCII编码需要多一倍的存储空间,在存储和传输上就十分不划算。 # 所以,... 阅读全文
posted @ 2019-09-18 16:41 ~清风煮酒~ 阅读(749) 评论(0) 推荐(0) 编辑
摘要: Python有以下主要的数据类型: 1. 字符串:用于表示文本数据,使用单引号'或双引号"包围。例如: python 'Hello' "World" 2. 整数:整型数据,可以是正数或负数。例如: python 100 -50 3. 浮点数:用于表示实数,使用小数点。例如: python 3.14 阅读全文
posted @ 2019-09-18 16:40 ~清风煮酒~ 阅读(155) 评论(0) 推荐(0) 编辑
摘要: print('test', '怎么自动建了这么多目录', 'aaaaaaa') #test 怎么自动建了这么多目录 aaaaaaa 注释# # a = 100 if a >= 0: print(a) #100 else: print(-a) # 转义 print('I\'m ok.') # I'm 阅读全文
posted @ 2019-09-18 16:34 ~清风煮酒~ 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 《快学Scala》心得体会 1 基础 1.1 声明和定义 Val无法改变它的内容,实际上就是一个常量 Var 声明其值可变的变量 在scala中,与java不同的是,变量或函数的类型总是写在变量或函数名称的后面。 1.2 常用类型 Scala有7种数值类型:Byte、Char、Short、Int、L 阅读全文
posted @ 2019-09-17 17:43 ~清风煮酒~ 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 在idea中新建工程 删除新项目的src,创建moudle 在父pom中添加spark和scala依赖,我们项目中用scala开发模型,建议scala,开发体验会更好(java、python也可以) 在我们Moudle中配置打包插件 安装scala开发插件到idea 安装后重启 设置scalasdk 阅读全文
posted @ 2019-09-17 16:54 ~清风煮酒~ 阅读(1702) 评论(0) 推荐(0) 编辑
摘要: 原文链接 引言 本文整理自工作多年以来遇到的所有 Git 问题汇总,之前都是遗忘的时候去看一遍操作,这次重新整理了一下,发出来方便大家收藏以及需要的时候查找答案。 一、必备知识点 image.png image.png 仓库 二、git add 提交到暂存区,出错怎么办 一般代码提交流程为:工作区  阅读全文
posted @ 2019-09-17 16:53 ~清风煮酒~ 阅读(270) 评论(0) 推荐(0) 编辑