f-string: the sexiest string

in StemSocial4 years ago

If you want to learn more about how to tame python you have come to the right post. Because this post is all about getting sexy with a string :D



Whenever I had a string into which I have to input something like length_rod = 8 I would type

"If you upvote this you have a {} inch rod".format(length_rod).

This pretty much inserts the lengthy rod where you want it. You can also reference them by index so

"I will hit {0} in the face for {1}".format('justin','free').

Reference parameters can be used together with .format exactly in the way you expect it

"Nobody expects {unexpected}".format(unexpected= 'the Spanish inquisition').

But you can imagine if it gets very long then things get complicated and confusing. There is also the %-formating which is something that all basic python tutorials treat but I think that's is only more ugly than .format. Anyway that f-string trumps all of these.

For an f-string everything is super simple. If you first define Sun = "Scum" then you can insert the assigned value to Sun into a string by just typing f"Justin {Sun}". Hence, the name f-string. Besides its simplicity you can also perform operations within a f-string this means that python is totally okay with you running

f"A whale p-nis is about {5*50} cm"

Of course you can also define something and use it within an f-string which is awesome. Anyway, hope that convinced you to use f-strings.

Here is a proper tutorial. ;)

Sort:  

Lets see:

hiver1 = 'mathowl'
hiver2= 'bluerobo'
witness= 'blue-witness'

print(f' Hey {hiver1}! {hiver2} has a new HIVE witness called {blue-witness}. You should totally vote for it ;) ')

 4 years ago  

That {blue-witness} should just be a witness :o)

 4 years ago  

I am actually not sure how to remove my witness proxy in hive since I cannot access my wallet. It apparently won't reset when I try to vote :/

You can go to your account on steeemworld.org, then go to settings and switch the node to anyx.io and then you can do all the hive things you like ;)

 4 years ago  

mission owlcomplished

owlsome. thanks

oh no!!!

coding is hard

hiver1 = 'mathowl'
hiver2= 'bluerobo'
witness= 'blue-witness'

print(f' Hey {hiver1}! {hiver2} has a new HIVE witness called {witness}. You should totally vote for it ;) ')

thanks for the socially distanced python lecture

get a room loosers

Its your independence day. Why so mad?

 4 years ago  

me.get('room')?

I love fstrings.

Did a tutorial in my Python Tips series a while ago.

You should also use #STEM or #TECHNOLOGY tags so you can get indexed by STEMGeeks and earn STEM Tokens. (Although Tribes have not moved over to Hive yet but for the future).

 4 years ago  

Thankies, I will do that. I still recommend you to press that tutorial button because the tutorial is rather unexpected :o)

This post has been voted on by the HiveSTEM curation team and voting trail. It is elligible for support from @curie and @minnowbooster.

If you appreciate the work we are doing, then consider supporting our witness @stem.witness. Additional witness support to the curie witness would be appreciated as well.

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Please consider using the stem.openhive.network app and including @steemstem as a beneficiary of this post. This could yield a stronger support.