python既問題

141 回覆
3 Like 28 Dislike
2020-10-05 00:36:50
想問下如果 想一個def用另一個def既值要點做

例如:

def A():
Ab= 1

def B ()
print(Ab)

咁B要點攞A既Ab
2020-10-05 00:38:53
A return value. Call A() from B then print out. 留意indentation
2020-10-05 00:39:46
def A():
return Ab = 1

def B():
print (A())

好似係 唔肯定
2020-10-05 00:40:15
點解要咁做?

一係golbal variable, 一係 function B call function A (function A return result)
2020-10-05 01:13:45
有冇例子 麻煩曬
2020-10-05 01:15:12
有冇例子 麻煩曬🙇🏻
2020-10-05 01:17:52
上面咪有人比左答案

def A()
return (Ab = 1)

def B()
print(A())
2020-10-05 01:27:23
做咩唔用class
2020-10-05 07:28:26
Python 冇inline assignment + evaluation,會出syntax error
2020-10-05 08:24:26
已經error中
2020-10-05 08:24:55
岩岩試左
2020-10-05 08:25:20
error中
2020-10-05 08:46:44
def __init__(self): 

        # Initialization of the Strings 

        self.String1 ="Hello"

        self.String2 ="World"

  

    def Function1(self): 

        # calling Function2 Method 

        self.Function2() 

        print("Function1 : ", self.String2) 

        return 

  

    def Function2(self): 

        print("Function2 : ", self.String1) 

        return
2020-10-05 08:47:41
try try the code what I just reply
2020-10-05 09:12:11
之前都係出Process finished with exit code 0
2020-10-05 09:28:10
我好似明明地 我再試就先 感謝
2020-10-05 09:28:30
# Instance of Class Main 

Object = Main() 

  
# Calling Function1 

Object.Function1()


未Call main
2020-10-05 10:15:02
Ab放出個function/
global Ab;Ab = 1/
return Ab <放係func A最後
2020-10-05 10:54:44
仲有其他問題想求教下大師 可唔可以私下救教?
2020-10-05 10:58:18
我都係Google咋,上面個問題解決到?
如果問題唔多呢到問都得 多問題先比Tg你啦
2020-10-05 11:04:40
解決到呀

不過我而加寫個個就冇用class但可以run到
但加左個class後就反而唔得
2020-10-05 11:11:25
以上個Method係適合用喺Within same class

如果你想其他CLASS都用到 你要用一個concept叫inherit

class Parent: 

  

    # constructor of Parent class 

    def __init__(self): 

        # Initialization of the Strings 

        self.String1 ="Hello"

        self.String2 ="World"

  

    def Function2(self): 

        print("Function2 : ", self.String1) 

        return

  
# Child class is inheriting from Parent class 

class Child(Parent): 

  

    def Function1(self): 

        # calling Function2 Method in parent class  

        self.Function2() 

        print("Function1 : ", self.String2) 

        return   

  
### Instance of Parent class 

Object1 = Parent() 

  
### Instance of Child class 

Object2 = Child() 

  
# Calling Function1 using Child class instance 
Object2.Function1() 
2020-10-05 11:15:34
我既意思係 我原本就冇class 但之後整左個class 張所以野放入去後就run唔到
2020-10-05 11:19:27
其實你不如唔好用class object住,寫返基本function calling算啦
吹水台自選台熱 門最 新手機台時事台政事台World體育台娛樂台動漫台Apps台遊戲台影視台講故台健康台感情台家庭台潮流台美容台上班台財經台房屋台飲食台旅遊台學術台校園台汽車台音樂台創意台硬件台電器台攝影台玩具台寵物台軟件台活動台電訊台直播台站務台黑 洞