Python Forum
help using functions from other files
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help using functions from other files
#4
(Dec-12-2018, 12:23 AM)lga13 Wrote: can you explain what the f on this line does?
f-string is the new string formatting(new in 3.6).
format() we have had since 26..
Example.
# older way
>>> first_name = "Eric"
>>> age = 30
>>> print('Name is:{} Age is:{}'.format(first_name, age))
Name is:Eric Age is:30
>>> 
>>> # The new way
>>> first_name = "Eric"
>>> age = 30
>>> print(f'Name is:{first_name} Age is:{age}')
Name is:Eric Age is:30
>>> print(f"Sammy has {4:4} red and {16:16}! blue balloons")
Sammy has    4 red and               16! blue balloons
 
>>> # f-strings support any Python expressions inside the curly braces
>>> name = 'f-string'
>>> print(f"My cool string is called {name.upper()}.")
My cool string is called F-STRING.
 
>>> a, b = 5, 7
>>> f'{a}/{b} = {a/b:.2}'
'5/7 = 0.71'
 
>>> for word in 'f-strings are awesome'.split():
...     print(f'{word.upper():~^20}')
~~~~~F-STRINGS~~~~~~
~~~~~~~~ARE~~~~~~~~~
~~~~~~AWESOME~~~~~~~
Reply


Messages In This Thread
help using functions from other files - by lga13 - Dec-11-2018, 11:28 PM
RE: help using functions from other files - by snippsat - Dec-12-2018, 12:46 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020