简体   繁体   English

如何在Python中定义变量

[英]How to define a variable in Python

I am a first time learner of Python and i am trying to define the variable a in my function. 我是Python的第一次学习者,我试图在我的函数中定义变量a。 How can i do it? 我该怎么做? Whenever i run this function, it says name 'a' is not defined. 每当我运行这个函数时,它都会说'a'这个名字没有定义。 and if there is anything more wrong, where did i get it wrong? 如果有什么更多的错误,我在哪里弄错了?

n= int(input ("choose your number >2     "))

def J(a,b):
    a = (n)
    b = (n-2)
    for (a) in range (n):
        for (b) in range (n-2):
            if a==b:
                print ()
def J(a,b):
    return math.factorial (a)// math.factorial (b)
size= J(a,b)
if size>40:
    a=input ("the pernutations would fill more than one screeen "
           +"still want to see th`enter code here`em all? yes or no    ")
    if a=="yes":
        print (J(a,b))
    if a=="no":`enter code here`
        print ()

You need to define a and b or replace them with values. 您需要定义ab或用值替换它们。 They act as placeholders for the values that are being inputted as your function caller. 它们充当作为函数调用者输入的值的占位符。 The a and b in the function are only local to the function, where when you call it, it sets the argument as the variable and treats it that way inside the function. 函数中的ab只是函数的本地函数,当你调用它时,它将参数设置为变量并在函数内部对待它。

a = "value" #replace with your value, if not string, remove quotes
b = "value"  
size = J(a,b)

or 要么

size = J(value1, value2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM