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

in programming •  last month 
# 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.
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

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