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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.