计算原理课程笔记(一)
<python>
"""
This is a docstring for the module:
This module demonstrates the use of docstrings.
"""
def repeat_string(string, num):
"""
This is a docstring for a function:
Return a new string that repeats the input
string num times.
"""
newstring = ""
for dummy_loop_counter in range(num):
newstring += string
return newstring
class SimpleCounter:
"""
This is a docstring for a class:
Simple counter class that can only increment.
"""
def __init__(self, initial_val = 0):
self._val = initial_val
def increment(self):
"""
This is a docstring for a method:
Increment counter.
"""
self._val += 1
def get_value(self):
"""
This is a docstring for another method:
Return current value of the counter.
"""
return self._val
<python>
<python>
import poc_helper_stuff as provided
import poc_mancala_testsuite
poc_mancala_testsuite.run_suite(SolitaireMancala)
import poc_mancala_gui
poc_mancala_gui.run_gui(SolitaireMancala())
<python>
导入poc_helper_stuff 模块
导入测试模块
导入gui模块
<python>
def __init__(self, initial_balance):
"""Creates an account with the given balance."""
self.banlance=initial_balance
self.fees=0
<python>
self.banlance
表示实例的变量
<python>
lst+=[lst[-3]+lst[-2]+lst[-1]]
<python>
[]
转化lst[-3]+lst[-2]+lst[-1]
为列表