Python Tricks #27 - f-strings Python3.6+

in #programming5 years ago
# f-strings are flexible way to do string interpolation available in Python 3.6+

# The old way with "format":
user = "Jane Doe"
action = "buy"
log_message = 'User {} has logged in and did an action {}.'.format(
      user,
      action
)
print(log_message)
# User Jane Doe has logged in and did an action buy.

# Instead of "format" after v3.6 we can use more flexible and readable way to do the same thing:
user = "Jane Doe"
action = "buy"
log_message = f'User {user} has logged in and did an action {action}.'
print(log_message)
# User Jane Doe has logged in and did an action buy.
Sort:  

I hope one day I understand what you explain here.

Posted using Partiko Android

Python Tricks are imagined to be short posts showing how much Python programming language is beautiful and powerful. I usually make them while I drink coffee warming up for work. ;)

If you are interested into coding, you can start with a tutorial. There are lots of good ones for free on edx.org, Coursera, Udemy and similar sites. Just search for one which suites best your learning process. You can try some of theses, these are absolutely free of charge:

https://www.edx.org/course/introduction-to-python-absolute-beginner-3

https://www.codecademy.com/catalog/subject/all
https://www.codecademy.com/learn/learn-python-3

https://www.udemy.com/python-for-absolute-beginners-u/

While drinking your coffee? Wow!

Thanks for the tips. I save the info and study it later.

Wish you a happy day with 💥 and 💖

Posted using Partiko Android

Simple concise example of how to simply use the new f-string formatting.
Thanks

Posted using Partiko Android

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.034
BTC 66931.79
ETH 3249.50
USDT 1.00
SBD 4.10