my_data={5,6,2,4}
print(type(my_data)) #<class 'set'>
my_data2=repr(my_data)
print(type(my_data2)) #<class 'str'>
print(repr(my_data)) #{5,6,2,4}
Output
<class 'set'>
<class 'str'>
{2, 4, 5, 6}
print(type(eval(my_data2)))
Output
<class 'set'>
my_str = """Hi"""
print(repr(my_str)) # Output: 'Hi'
print(str(my_str)) # Output: Hi
#eval(str(my_str) == my_str) # Gives a SyntaxError
print(eval(repr(my_str)) == my_str) # Output: True
import datetime
today = datetime.datetime.now()
print(str(today)) # Output: '2022-05-03 18:36:44.459740'
print(repr(today)) # Output: 'datetime.datetime(2022, 5, 3, 18, 36, 44, 459740)'
Output
2022-05-03 18:36:44.459740
datetime.datetime(2022, 5, 3, 18, 36, 44, 459740)
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.