Skip to content

Instantly share code, notes, and snippets.

@broject
Created January 17, 2018 04:05
Show Gist options
  • Save broject/22486aa1b1138f0a6d3381e4162f17f3 to your computer and use it in GitHub Desktop.
Save broject/22486aa1b1138f0a6d3381e4162f17f3 to your computer and use it in GitHub Desktop.
tuple vs list vs dict, repr vs str with eval cast
class Point3D(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __repr__(self):
return str(self.z)
def __str__(self):
return "(%s, %s, %s)" % (self.x, self.y, self.z)
my_point = Point3D(1, 2, 3)
print(my_point)
v = str(repr(my_point))
b = isinstance(v, str)
if b:
v1 = int(v) + 1
s = str(v1) + ';'
print(s)
else:
print(b, ";")
print(isinstance(('a', 'b'), tuple))
print(isinstance(['a', 'b'], list))
dic = {'abc': 'abc', 'def': {'a1': 'a1v', 'a2': 'a2v'}}
for elem in dic.values():
if isinstance(elem, dict):
for ndx, item in elem.items():
print(ndx, ' => ', item, 'is ')
for i in item:
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment