INFO1110 Oral Exam考試_ 完成進度6/33
- 前言
- Review :
- 1. Iterator vs Iterable
- 2.True or False: local variables only exist within the scope of a function
- 3.What is a pure function (week 5 lab sheet)
- 4.What are side effects of a function( week 5 lab sheet)
- 5.What is initializing
- 6.What is declaring a variable
- 7.What is the difference between `==` and `is`
- 8.What are the advantages of using `if`-`elif`-`else` rather than a bunch of `if` statements
- 總結
前言
下面內容來自ED,Week12,小編會以筆記的方式去講解,如有錯誤及時聯系我及時更正,爭取在11月26號(周四)之前完成,
Review :
1. Iterator vs Iterable
iterator: stream of data
iterable: sequence that you can iterate through
講解: iterator中文意思為迭代器,表示資料流的物件,iterable中文意識是可迭代,一個能夠一次回傳其成員的物件
資料鏈接1: iterator 和 iterable的關系
資料鏈接2: iterator 和 iterable的解釋
2.True or False: local variables only exist within the scope of a function
def function():
a = 5 #local variable
print(a) #NameError
Answer: True
講解: 標題意思為區域變數僅存在于函式范圍內,判斷是否正確,首先我們要了解什么是Local variable.中文意思為區域變數,在函式體內或區域范圍內宣告的變數稱為區域變數,
上面程式中的a=5就是local variable,在自定義函式范圍內運行,如果跳出函式,運行時就會報錯為’NameError: name ‘a’ is not defined‘,
local variable 解釋: local variable 講解
3.What is a pure function (week 5 lab sheet)
function with no side effect
講解: 問什么是pure function,中文意思為純函式,一個純粹的功能不會產生副作用,
pure function解釋: pure function 的解釋
解釋2: pure function
4.What are side effects of a function( week 5 lab sheet)
modifying data that are passed in or global variables (use global)
a = 5
def function():
print(a) #can read global variable
#modify global variable
global a
a += 1
解釋: 問題問功能的副作用是什么(沒必要記住中文什么意思,中文只是輔助記憶,主要還得是英文)?修改傳入的資料或全域變數(使用全域)
很細致的講解side effects of a function: side effects鏈接
Side Effects講解: Side Effects
Side Effects in Python: Side Effects in Python
ED課件講解: week5lab_5.0_part4 (登錄ed后能看見)
5.What is initializing
assigning value to a variable
解釋: 什么是初始化,給變數賦值,(可能__init__就是初始化,下面鏈接里有詳細資料),
Initializing variable in python: Initializing
6.What is declaring a variable
creating the variable
a = True
b = False
a and b -> True and False -> False
a or b -> True or False -> True
a and b or a -> True and False or True -> False or True -> True
a or b or c -> True or False or ? -> True or ? -> True because of short circuit
a and b or c -> False or c -> NameError
a and b and c -> False and c -> False because of short circuit
- ()
- not
- and
- or
解釋: 什么是變數宣告,就是創建變數,a為True,b為False, 如果有and表示都正確,運行,遇到false整個條件判斷為false,or 就是兩者有一個為true就可以運行,
declearing variable: Python Variable
python variable declaration: variable
7.What is the difference between == and is
is : always compare the memory address
== : values unless you’re dealing with object
"hello" == "hello"
解釋: 問==和is在程式里的區別,is是判斷兩者是否參考同一個物件(參考地址),==是判斷兩者的值是否相等,
is ==用法: 兩者用法鏈接
difference: 不同用處
8.What are the advantages of using if-elif-else rather than a bunch of if statements
if a == 5:
do something
if a == 6:
do something
if a == 7:
do something
if a == 5:
do something
elif a == 6:
do something
elif a == 7:
do something
this one is faster
解釋: 問用if-elif-else而不用if-if-if的好處,程式運行的更快捷,前者程式要檢查每一個if模塊,后者直接條件判斷,
if-elif-else用法: 菜鳥教程的用法-中文
用法教程: Programiz的用法-英文
What is a flow chart
chart describing flow / structure of the code
contains diamonds (decisions) and rectangles
What is a desk check
keep track of how variables changes throughout program
use it for debugging
make sure you have a column for every variable and one for output
What datatype is mutable in python
list, class, dictionary
What datatype is iterable in python
list, dictionary, iterators
dict = {"key":[], "key2":"value"}
What is the difference between []*5 vs [0]*5
length of []*5: 0
length of [0]*5: 5
a = [1,2, 3, 4, 5, 6]
for i in a:
i += 1
What does a store at the end of this code snippet?
no. for loops are read only
a = [1,2, 3, 4, 5, 6]
for i in range(len(a)):
a[i] += 1
Describe the differences between black box testing and white box testing
white box: sees code
end to end is black box?
What is a module lecture 14 slide 4
sys, math, random
predefined code / program that allows you to do …
import the modules so you can use the functionalities inside
How do you modify a global variable in Python
global
True or False, you always have to close a file after reading or writing them. If not, when can you get away with it?
f = open("text.txt")
df = f.readlines()
file isn’t closed, file could be corrupted
with open("text.txt") as f:
df = f.readlines()
Python close automatically
What is sys.stdout?
sys.stdout == print
True or False: Tuples are mutable
False
f = (1, 2, 3)
f = (2, 3, 4)
this one is actually pointing to a different address entirely
How do you do x^4 in Python without importing Math module?
x**4
True or False: A function does not have to return anything
False because a function always returns None when user doesn’t define a return
True or False: A tuple can vary in size
a = (1, 2, 3)
a = (1, 2, 3, 4) #works
a.append(5) #this won't work because tuples are immutable
No a tupe cannot vary in size unless change memory location
Describe the differences in lists and arrays
lists : separately but they contain address of the next element , can vary in datatype, can change in size (use append)
arrays : stored together, can only have one datatype, can’t change size, can jump from one element to another
What happens when you try to create an object from a class that doesn’t have a pre-defined constructor?
a blank constructor is generated in background
By default, what gets printed when you print an object?
if didn’t write __str__() : <datatype, memory>
after writing __str__(): prints out the output you define
By default, what does Python compare when you compare two objects?
if didn’t write __eq__(): compares memory address
if you did write __eq__() : this one compares the variables that you define
What is the difference between static, class and instance methods?
instance : self, referring to the instance
class : cls, refers to the whole class, one change can change it for every instance of the class
static : doesn’t take in anything in parameter,
True or False: A function can have multiple returns
True
def function(a): #a is a boolean
if a:
return True
else:
return False
Why is testing important?
to make sure your code is running as it should
types of testing : end to end, unit testing, integration testing
black box, white box
What is integration testing?
checking whether connection of two or more systems are working
How do you perform end-to-end testing?
diff ____ ____
What is regression testing?
testing every test cases (previous and current phases) as you progress through the solution
總結
提示:最近期末,作業多 任務多,我會盡快更新,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/227533.html
標籤:python
上一篇:多執行緒賣票問題
