how to use a string variable as a variable name in python
#works only inside classes
name = 'varname'
value = 'something'
setattr(self, name, value) #equivalent to: self.varname= 'something'
print (self.varname)
#will print 'something'
how to use a string variable as a variable name in python
#works only inside classes
name = 'varname'
value = 'something'
setattr(self, name, value) #equivalent to: self.varname= 'something'
print (self.varname)
#will print 'something'
how to create a variable in python
variable1 = "value" # string
variable2 = 1000000 # integer
variable3 = 10000.0 # real/float
variable4 = True # boolean: True or False
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us