-1

So i've tried the formats string methods in python but what are the differences between them? Which method is best for me?

example1: name = 'Dash'

print(f'Hello {name}!')

example2: name = 'Dash'

print('Hello {}!'.format(name))

PyperDash
  • 1
  • 4
  • 1
    There is no difference as you see. Both are string formatting options, with f-strings being newly introduced. – Austin Aug 15 '20 at 09:57

2 Answers2

2

Effectively both do the same thing. The f you mention is an f-string which is available from python 3.6

Eliran Turgeman
  • 1,526
  • 2
  • 16
  • 34
1

Print f is just a newer and easier way of inserting a variable into a string. I think it came in in python 3.6 . Both do really the same thing

Dunski
  • 653
  • 5
  • 14