I am new to python programming. I have written sample code as flows.
temp.py
p = 'Tushar'
print(p)
class Basics:
def __init__(self, name, phNum):
self.name = name
self.phNum = phNum
def getString(self):
temp = self.name+' '+str(self.phNum)
print(type(temp))
return temp
bs = Basics("tushar", 9620207652)
x = bs.getString()
print(x)
def isBlue(isBlue):
if(isBlue):
print('Boolean true')
x = 'true'
else:
print('Boolean false')
x = 'false'
return x
tus = isBlue(True)
if(tus != None):
str = bs.getString().split(' ',1)
print(str[0])
print(str[1])
Hello.py
from temp import Basics
class Check:
def __init__(self):
print('Check obj')
def createName(self, firstName, lastName):
str = firstName + ' ' + lastName
return str
emp = Check()
completeName = emp.createName('Tushar', 'Banne')
print(completeName)
b = Basics('Tushar', 98765432)
val = b.getString
print("Val is {}".format(val))
I am running Hello.py file and getting the below output.
Tushar
class 'str'
tushar 9620207652
Boolean true
class 'str'
tushar 9620207652
Check obj
Tushar Banne
Val is (bound method Basics.getString of 0x0000024ECCCB5B70
The questions that I have are as follows
Why is the entire temp.py getting executed?
How to execute only getString method.
Why is it that when I use parenthesis after getString, it fails.
Why is the
val
printing object reference?Am I following the correct standards of python coding?