Created
January 17, 2018 04:05
-
-
Save broject/22486aa1b1138f0a6d3381e4162f17f3 to your computer and use it in GitHub Desktop.
tuple vs list vs dict, repr vs str with eval cast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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