Oct-15-2019, 09:40 AM
Hi!
It seems that I cannot fully understand f-strings. I do exercises and little programs trying to update them by using f-strings, but now and then, I keep having some problems.
For instance, I wrote this little program:
2) Is there a good tutorial FOR DUMMIES or FOR NEWBIES on all the details of f-strings?
I like Metulburr's basic tutorial:
https://python-forum.io/Thread-Basic-f-s...xpressions
I wish there would be a longer, deeper one, but easy enough to follow and understand by thickheads like myself.
Thanks and all the best,
It seems that I cannot fully understand f-strings. I do exercises and little programs trying to update them by using f-strings, but now and then, I keep having some problems.
For instance, I wrote this little program:
# atbs_04_commaCode_01.py # # It works. # def commaCode(list1): print("'", end='') print(*list1[:-1], sep=', ', end=",") print(' and', list1[-1], end=".'\n\n") spam1 = ['apples', 'bananas', 'tofu', 'cats'] commaCode(spam1) eggs1 = ['bird', 'dolphin', 'whale', 'parrot', 'gorilla', 'dog'] commaCode(eggs1) numbers1 = [1, 2, 3, 4, 5] commaCode(numbers1)that works and produces the following output:
Output:'apples, bananas, tofu, and cats.'
'bird, dolphin, whale, parrot, gorilla, and dog.'
'1, 2, 3, 4, and 5.'
>>>
1) Is there a way to simplify the 3 lines of print with f-strings?2) Is there a good tutorial FOR DUMMIES or FOR NEWBIES on all the details of f-strings?
I like Metulburr's basic tutorial:
https://python-forum.io/Thread-Basic-f-s...xpressions
I wish there would be a longer, deeper one, but easy enough to follow and understand by thickheads like myself.
Thanks and all the best,