小编use*_*080的帖子

Python3替换使用字典

谁能解释一下这里有什么问题:

def get_complementary_sequence(string):
    dic = {'A':'T', 'C':'G', 'T':'A', 'G':'C'}
    for a, b in dic.items():
        string = string.replace(a, b)
    return string
Run Code Online (Sandbox Code Playgroud)

我得到'T'和'C'的正确结果,但'A'和'C'不会取代.真的卡住了.

字符串看起来像'ACGTACG'.

python string replace python-3.x

3
推荐指数
1
解决办法
1019
查看次数

为什么以下代码会导致错误?

它适用于Employeecalculate_wage,但当我尝试创建一个实例PartTimeEmployee并调用其父类的calculate_wage方法时返回错误PartTimeEmployee.

class Employee(object):
     """Models real-life employees!"""
     def __init__(self, employee_name):
         self.employee_name = employee_name

     def calculate_wage(self, hours):
         self.hours = hours
         return hours * 20.00

 class PartTimeEmployee(Employee):
     def __init__(self, employee_name):
         self.employee_name = employee_name
     def calculate_wage(self, hours):
         self.hours = hours
         return hours * 12.00
     def full_time_wage(self, hours):
         return super(PartTimeEmployee, self).calculate_wage(self, hours)

 milton = PartTimeEmployee("Milton")
 print (milton.full_time_wage(10))
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
115
查看次数

标签 统计

python ×2

python-3.x ×1

replace ×1

string ×1