Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1584

Python • Re: print .. end="" not working

$
0
0
({datetime.now()}
There are unexpected curly braces... perhaps this is the problem?
That intrigued me, had me wondering what a {...} sequence meant which I had never encountered before except for dictionaries ...

Code:

Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> {1}{1}>>> type({1})<class 'set'>
Which took me to - https://www.w3schools.com/python/python_sets.asp

I presume the OP is using that to show the individual parts of 'datetime.now' -

Code:

>>> from datetime import datetime>>> print({datetime.now()}){datetime.datetime(2025, 7, 9, 12, 39, 45, 414190)}>>> print(datetime.now())2025-07-09 12:39:46.149957
What it seems to be doing is creating a single item set, with that item shown using a 'repr()' rather than 'str()' to make it readable and meaningful -

Code:

>>> print(repr(datetime.now()))datetime.datetime(2025, 7, 9, 12, 44, 14, 968972)
With the {...} added because it's printing that as a set.

Statistics: Posted by hippy — Wed Jul 09, 2025 11:42 am



Viewing all articles
Browse latest Browse all 1584

Trending Articles