Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python __init__(自)相关方法的结果未显示_Python_Python 3.x - Fatal编程技术网

Python __init__(自)相关方法的结果未显示

Python __init__(自)相关方法的结果未显示,python,python-3.x,Python,Python 3.x,当我编写emp_1.pay_raise()短语或emp_1.fullname()时,无论是在pycharm中按“run”还是“debug”,我都不会得到任何结果或错误。你能注意到我的代码中有错误吗?我将非常感谢。您没有打印出执行这些方法的任何“结果”。试试这个: class Employee(object): def __init__(self, first, last, pay): self.first = first self.last = last

当我编写emp_1.pay_raise()短语或emp_1.fullname()时,无论是在pycharm中按“run”还是“debug”,我都不会得到任何结果或错误。你能注意到我的代码中有错误吗?我将非常感谢。

您没有打印出执行这些方法的任何“结果”。试试这个:

class Employee(object):
    def __init__(self, first, last, pay):
        self.first = first
        self.last = last
        self.pay = pay
        self.email = first + '.' + last + '@company.com'

    def fullname(self):
        return '{} {}'.format(self.first, self.last)

    def pay_raise(self):

        self.pay = int(self.pay * 1.04)


emp_1 = Employee("Mark", "Johnson", 50000)

emp_1.pay_raise()

pay\u raise
不返回值;它只更改一个属性。您从未调用过
全名
。这与
\uuuuu init\uuuuu
无关。我希望此程序运行时不会出错,也不会有输出。你还有别的结果吗?我确实没有结果。程序运行时也没有任何错误。您根本不打印任何结果。
class Employee(object):
    def __init__(self, first, last, pay):
        self.first = first
        self.last = last
        self.pay = pay
        self.email = first + '.' + last + '@company.com'

    def fullname(self):
        return '{} {}'.format(self.first, self.last)

    def pay_raise(self):

        self.pay = int(self.pay * 1.04)


emp_1 = Employee("Mark", "Johnson", 50000)

print(emp_1.fullname())

emp_1.pay_raise()
print(emp_1.pay)