Posts: 4,642
Threads: 1,492
Joined: Sep 2016
i know i have seen this before but now that i have a use case, i can't find it.
Output:
>>> foo(3.25)
'3.25'
>>> foo(4.0)
'4'
>>>
i want to find what works like foo() in this fake example.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,642
Threads: 1,492
Joined: Sep 2016
i thought i had seen it as a single function. i want to do this in an f-string. i want to keep it simple. maybe it was something i had coded a long time ago like answer #3 in that link.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,642
Threads: 1,492
Joined: Sep 2016
close to that. while str() isn't exactly necessary, that was what i had in mind ... that foo() did the formatting.
def foo (floating_point_number) :
integer = int (floating_point_number)
if integer == floating_point_number :
return str(integer)
return str(floating_point_number)
print (f'{foo (3.25)}, {foo (4.0)}')
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,642
Threads: 1,492
Joined: Sep 2016
not to print in the function since i may want 2 or more on the same line. i may or may not need a str returned.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.