廖雪峰Python 类类init方法12345678虽然实例属性可以后期动态添加,但是也可以通过__init__初始化方法绑定成员变量。self参数表示指向创建的实例可以没有init方法class Student(object): def __init__(self, name, score): self.name = name self.score = score
访问限制1234成员变量前面加上两个下划线,变成私有属性:外部无法通过 .__属性 访问。之所有无法通过.__属性访问的原因是,解释器会把__属性改名成其它的名字(不同的解释器有可能不同),例如:_类名__属性通过方法操作成员变量,可以实现逻辑检查
继承和多态123class Animal(object): def run(self): print('Animal is running...')
1234567重写父类方法class Dog(Animal): def run(self): print('Dog is ...
廖雪峰Python 函数函数函数参数1函数调用时可以按位置参数传参,也可以写明参数名传参
123456789python函数可以返回多个值(其实是一个值,返回的一个tuple),sql和java类函数只能返回一个值>>> r = move(100, 100, 60, math.pi / 6)>>> print(r)(151.96152422706632, 70.0)>>> x, y = move(100, 100, 60, math.pi / 6)>>> print(x, y)151.96152422706632 70.0
12345678910位置参数:函数调用时传参顺序要和函数定义时的参数顺序一样必选参数:调用时必须传值的参数默认参数:默认参数放在必选参数后面可变参数:*nums,函数内部nums变成了tuple,可以用循环迭代,参数list,tuple在前面*def calc(*numbers): sum = 0 for n in numbers: sum = sum + n * ...
廖雪峰Python 错误类型ValueError1234def set_gender(self, gender): if gender not in ('male', 'female'): raise ValueError('gender must be male or female') self.__gender = gender
TypeError1234>>> abs(1, 2)Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: abs() takes exactly one argument (2 given)
廖雪峰PythonJava对比学习1语言类型1java是javac编译器先编译成字节码.class文件,后java虚拟机解释生成机器码执行
123intellij idea使用pythonhttps://www.oryoy.com/news/intellij-idea-pei-zhi-python-kai-fa-huan-jing-cong-an-zhuang-dao-diao-shi-quan-zhi-nan.html
12静态语言java动态语言python
输入和输出python1python里输入input,输出print
java1scanner.nextInt() nextFloat() next() nextLine()
123456789101112131415java里输入:import java.util.Scanner;public class test { public static void main(String[] args) { Scanner input = new Scanner(System.in) ...
廖雪峰Python字符串12'xx'.lower() .upper()
面试题https://zhuanlan.zhihu.com/p/270331009
Python库time12345678910import time# 打印时间戳print(time.time()) # 自1970年1月1日午夜(历元)以来的秒数# 打印本地时间print(time.localtime(time.time())) # 本地时间# 打印格式化时间print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) # 格式化时间
123456789import datetime# 打印当前时间time1 = datetime.datetime.now()print(time1)# 打印按指定格式排版的时间time2 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')print(time2)
sysfu ...
廖雪峰java-Spring Boot开发 1123Spring Boot是一个基于Spring的套件,它帮我们预组装了Spring的一系列组件,以便以尽可能少的代码和配置来开发基于Spring的Java应用程序。Spring Boot和Spring的关系就是整车和零部件的关系
第一个Spring Boot应用
1spring结构下面
application.yml使用环境变量logback-spring.xmlstatic、templates1static是静态文件目录,templates是模板文件目录,注意它们不再存放在src/main/webapp下,而是直接放到src/main/resources这个classpath目录,因为在Spring Boot中已经不需要专门的webapp目录了。
代码结构
12345678在存放源码的src/main/java目录中,Spring Boot对Java包的层级结构有一个要求。注意到我们的根package是com.itranswarp.learnjava,下面还有entity、service、web等子package。Spring ...
廖雪峰java-Spring Cloud开发 1
廖雪峰java-Web开发 1123java eejave sejave me
12j2eeservlet
Web基础1B/S
HTTP协议12345678htmltcpHTTP/1.1服务器的响应、浏览器发送的HTTP请求遇到两个连续的\r\n2xx表示成功,3xx表示重定向,4xx表示客户端引发的错误,5xx表示服务器端引发的错误编写服务器程序来处理客户端请求通常就称之为Web开发。
编写HTTP Server123456789我们来看一下如何编写HTTP Server。一个HTTP Server本质上是一个TCP服务器,我们先用TCP编程的多线程实现的服务器端框架:实现一个最简单的Servlet通过Maven来引入它warServlet版本 4.0 5.0Tomcat版本 9.0 10.0整个工程结构支持Servlet API的Web服务器
Servlet入门12345678910最简单的ServletServlet API是一个jar包,我们需要通过Maven来引入它war整个工程结构支持Servlet API的Web服务器Servlet版本 4.0 5.0Tomca ...
廖雪峰spring-1spring 开发IOC容器IOC原理1inversion of control
依赖注入方式1方法或者构造方法
无侵入容器1
装配Bean123xml方式IOC容器可使用ApplicationContext、BeanFactory
使用Annotation配置12345@Component@Autowired 可以写在构造方法、字段、方法里@Configuration@ComponentScan
定制Beanscope12@Component@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
注入List123456789101112131415161718@Componentpublic class Validators { @Autowired List<Validator> validators; public void validate(String email, String password, String name) { for ...
哈希算法哈希碰撞哈希算法的用途md5sha-1sha-256sha-512






