A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Wendy0518 初级黑马   /  2019-5-31 17:49  /  921 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

# 0327day2

boolean (?)True or False 1 or 0

Uppercase

shortcut .print

in variable assignment, left side of operand = must be variable, the right side could be already defined variable or value

###### case

## ![1553736274967](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553736274967.png)

remark: 复合运算 eg: += can't be used over 1 time in one expression

###### case

![1553736523736](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553736523736.png)

复合运算中 left side operand should be defined too(eg: a+=b means a= a+b)

###### case

![1553736462678](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553736462678.png)2**3=8

8**(1/3)=2



string

can combine two or more string with +, but can't combine string and number



input is a waiting function, 阻塞 function, until user type sth, program continues

default result of input is string

数据类型转换

string change to number type, special rule



input() 输入数值为 float时, 不可以用int(input())“123.0”不可以转化成123

input() 输入数值为int 类型时,可以用float(input()) 转化类型

input()如果包含字母等不可转化的话,不能用int float

###### case 01

![1553735785867](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553735785867.png)

![1553690284903](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553690284903.png)

try to avoid multi usage of ( ) in one expression



% can both used in print and variable assignment

print("  %d  " % variable)

![1555155619800](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1555155619800.png)

![1555155710549](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1555155710549.png)

![1555155875448](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1555155875448.png)

###### case

![1553737342408](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553737342408.png)



![1553666671258](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553666671258.png)

> ###### case(%.2f  means 四舍五入保留2位小数)
>
> ![1553737545051](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553737545051.png)
>
>
>
> ###### case(%s same)
>
> ![1553737699004](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553737699004.png)
>
> = <=  only compare same class

lowcase > uppercase



start comparison from 1st character, if it's smaller, then the whole string is smaller.



![1553670912211](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553670912211.png)

![1553670974146](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553670974146.png)



**" " true and "" false**

###### case

![1553743822317](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553743822317.png)

![1553740087409](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553740087409.png)

if clause

: means end of conditional expression

it's ok to print 95 <= score = 100



container中的不能类型element不能比较,不能用max min()



![



1553675159586](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553675159586.png)

![1554718772489](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554718772489.png)



# 0329day3

while循环



![1553857961976](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553857961976.png)



循环变量i start from 0 usually and it's not necessary

notice the position of i

![1553828836744](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553828836744.png)

print(value, end=(""))  end default is "\n"

\n can only be used in string

![1553858729398](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553858729398.png)

![1553909748987](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553909748987.png)

while嵌套

![1553859066398](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553859066398.png)

函数 function



![1553866150329](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553866150329.png)

函数调用

![1

553860754359](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553860754359.png)

#### **2.****2****形参****和实参**

形参是函数定义时规定的参数,仅在函数体内有效

实参是函数调用时使用的参数,该值将传递给函数![1

553906606379](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553906606379.png)

![1553906720494](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553906720494.png)

###### case



![1553996663350](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553996663350.png)参数规则



![1553997160104](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553997301514.png)

![1553866428734](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553866428734.png)

###### case



![1553860992928](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553860992928.png)

![1553910064877](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553910064877.png)

全局变量与局部变量

###### case



![1553861462919](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553861462919.png)

![1553861476796](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553861476796.png)





![1553867508059](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553867508059.png)

函数参数 optional argument and required argument, positional argument

###### case



![1

when def function, can only use variable as parameter, can't be value

553906489780](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553906489780.png)

![1553907280062](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553907280062.png)



###### case: 函数return值和变量接收



![1553998196344](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553998196344.png)

###### ![1553998419738](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553998419738.png)case

![1553998534069](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553998534069.png)

###### ![1553909408600](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553909408600.png)

###### case函数调用记得return

![1554000352194](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554000352194.png)

###### case

函数定义时内部函数体不执行,调用时才执行,如果有global declaration, 可以改变调用函数前的global variable

![1554025512246](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554025512246.png)

![1554026324005](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554026324005.png)

###### case



![1554027948723](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554027948723.png)

![1554028048857](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554028048857.png)





# 0330day4



![1555158117066](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1555158117066.png)



![1553911397978](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553911397978.png)

![1

553911630391](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553911630391.png)

\![1553917535853](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553917535853.png)

![1553917565681](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553917565681.png)

str method can only return string value

__str__ method  (return并不打印结果,需要print函数)

###### case

![1553928743213](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553928743213.png)

###### case

__init__method

![1553930168828](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553930168828.png)

![1553942213501](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553942213501.png)

![1553942236606](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1553942236606.png)

# 0401day5

![1554255861650](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554255861650.png)

![1554255983428](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554255983428.png)

###### case

![1554255956078](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554255956078.png)



![1554105703857](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554105703857.png)



![1554116778985](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554116778985.png)



多态: share same parent Class, use same instance method, but return different value

![1554123620779](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554123620779.png)

![1554165109452](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554165109452.png)

![1554165451289](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554165451289.png)

实例方法重写



![1554165703101](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554165703101.png)

![1554165747835](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554165747835.png)

![1554810868576](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554810868576.png)

![1554812414263](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554812414263.png)



![1554812504145](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554812504145.png)

![1554899824115](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554899824115.png)静态方法不需要cls, self传参,但是调用需要class name or instance name  

![1555158340298](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1555158340298.png)



# 0402day6

# ![1554199455314](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554199455314.png)

![1554900521854](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554900521854.png)浅拷贝

![1554901993610](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554901993610.png)

![1554903828249](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554903828249.png)

格式转换是创建了另外一个格式的类的实例



![



1554715082586](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554715082586.png)

![1554715808525](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554715808525.png)



![1555159225887](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1555159225887.png)

for 遍历字典

![1554716552338](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554716552338.png)

![1554716849699](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554716849699.png)

![1554716929500](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554716929500.png)

![1554719430562](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554719430562.png)

![1554719484136](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554719484136.png)

container 比较发生在同种type container之间,且两个container内的数据为同一种类型,从左到右依次比较

![



1554720799780](C:\Users\Wendy\AppData\Roaming\Typora\typora-user-images\1554720799780.png)

#### for else基本语法

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马