by Grue3 · 7y ago · 0 comments
What happened to "explicit is better than implicit"? "Only one way to do stuff"? One of the more baffling Python features if you ask me.
> name = ‘Jane’
> print(f”Hello, {name}”)
and PHP’s:
> $name = “Jane”;
> echo “Hello, $name”;
PHP:
print("Hello, $name")
print("Hello, ${getName()})
Python: print(f"Hello, {name}")
C# Console.WriteLine($"Hello, {name}")
Javascript Console.Log(`Hello, ${name}`)
Ruby puts "Hello, #{name}"
etc.However I think it's fair to credit PHP with introducing generations of programers to the idea.
> name = 'Jane'
> print 'Hello, %s' % (name)
but I can't exactly reproduce all the discussions from back then. As for me personally I can see that I dislike the new
> print(f'Hello {name}')
format because my editor cannot instantly show me that {name} is in a fact a variable, and now that I wrote this down I remember that this was one of the complaints made against PHP's use of "Hello, $name" . But maybe newer editors do in fact recognize {name} as a Python variable, in any case it looks and feels "impure", for a lack of a better word.