Questions tagged [f-string]

Literal string interpolation in Python

An f-string is the abbreviated name for a "formatted string" syntax that was introduced in Python 3.6 and extended in Python 3.7. They enable literal string interpolation:

>>> value = 80
>>> f'The value is {value}.'
'The value is 80.'

See PEP 498 for a comprehensive description of the feature, and also PEP 536 for the final grammar.

621 questions
-3
votes
1 answer

output contents of dict to specified text format

I have a dictionary with the following information dict = {'key1':['1:2','2:3','3:4'], 'key2':['4:5','5:6']} I need to out put this to a text file using the following format, the key and its values are to be commar seperated, with no '' quotation…
Pythonuser
  • 203
  • 1
  • 11
-3
votes
1 answer

Why are f-strings not printed in Python class methods?

I would like to understand why f-strings do not print output in class methods. I would like to use their concise syntax for making breakpoints. MWE: class FStringTest: def test(self): print('why does this work') f'but not…
-3
votes
1 answer

Moving Averages In pandas with f-string

How could i calculate a rolling average with f-stringed columns? Normally it's: df.columns=['x','y'] rollingaverage = df.y.rolling(window=6).mean() How do I do implement this given I use f-string? This didn't work: concatted apple_y banana_y …
arv
  • 398
  • 1
  • 9
-4
votes
1 answer

google cloud doesn't work with previous f-string python

I'm trying to connect to google cloud and i've set the python code as follows: import google.cloud import storage bucket_id='my_bucketname' //others variables storage=f'gs://{bucket_id}/' client = storage.Client() But, I've had the error: client…
Pinheiro
  • 13
  • 4
-4
votes
1 answer

Taking user input, calculations with said input and producing an output using f-strings

I am trying to code a program that will ask the user for their name and age and return how long until they turn 100 years old. I keep getting errors and I can't understand what I am doing wrong. Here is the more basic code I have changed it to try…
TechSlugz
  • 1
  • 3
-4
votes
1 answer

Why is that Python 3 IDE in some sites doesn't support f string function?

f string function print(f"{theString}") makes it easier to print the string than this print("{}".format(theString)) But Python 3 compiler in certain sites doesn't support this function. Is there some specific version of Python for this function to…
abhijithvijayan
  • 835
  • 12
  • 17
1 2 3
41
42