如何在方法中声明变量(Python)

时间:2017-09-09 04:01:24

标签: python function methods

def intro():
   print("This program computes payroll based on")
   print("over time rate of ", overTime, " after ", workWeek, " hours")
   name = input("Enter employees name: ")
   hours = (int(input("Enter hours worked: ")))
   rate = input("Enter rate: ")

enter image description here

1 个答案:

答案 0 :(得分:1)

虽然它被认为是一种不好的做法,但在大多数情况下你应该避免使用全局变量,你可以使用" global"在函数内部到达变量。

像这样:

global name
name = input("string")