Maybe Love, Part II

Maybe Love, Part II 

This is another post dedicated to Weyes Blood's "Maybe Love". But right now I am actually listening to Lana del Rey's "Jon Batiste Interlude" on repeat. I LOVE this song. I can never get tired of it. And here is a picture of a pylon near my house:

A pylon on a hill in nice sunny weather with a clear blue sky as a background. There is a tree to the side of the pylon.

String Methods

I have just finished my lesson on string methods in Python. I didn't do the off platform project but that doesn't feel like my priority right now. I feel like I just want to move through the course as fast as possible.

And just learn the syntax. I can come back to the off-platform project later if I like but this might not be my top priority for right now.

What string methods have I learned? Any interesting ones in particular?

.split()

Splits a string into a series of list items on a list. You can specify what you want to split by in the brackets, if left blank it just splits on spaces.

susanna_string = "Susanna likes cuddly soft dragons"

susanna_list = susanna_string.split()

print(susanna_list)

# Output: ['Susanna', 'likes', 'cuddly', 'soft', 'dragons']

.strip()

Strip clears away all the whitespace you don't want, or any other characters.

.format()

Format allows you to insert values of variables into a string. It is really, really cool. It could look something a bit like this:

susanna_text = "Susanna really likes {} and {}!"

print(susanna_text.format("pylons", "offshore wind farms"))

# Output: Susanna really likes pylons and offshore wind farms!

I really like this one. There is a lot more you can do with it. Like specifying the names of different types of values, and therefore being able to change the input of parameters, and so on. Just a really really super fun method, all in all!

.replace()

I really like this one too, similar to .format(). I like words. I like strings. I like mad libs. I like anything that plays around and messes around with words.

susanna_string = "susanna is the best and fabulous. susanna is so so awesome. susanna is the best yes yes yes and thank you - yes."

henry_string = susanna_string.replace("susanna", "henry")

print(henry_string)

#Output: henry is the best and fabulous. henry is so so awesome. henry is the best yes yes yes and thank you - yes.

Henry being my former Engineering Mentor - a Senior Engineer. Perhaps I will send this to him later! Thank you. 💜

.find()

This method finds the index of the first instance of what you are searching for in the string. You can search by string in the brackets.

.join()

This method joins a list and turns it into a string. It can only be called on lists though and so the syntax is slightly different. 

bletchley_park_list = ["this", "is", "a", "really", "cool", "place"]

bletchley_park_sentence = " ".join(bletchley_park_list).capitalize()

print(bletchley_park_sentence)

# Output: This is a really cool place

I learned .upper(), .title(), and .lower() too - and note that I have included .capitalize() in the example above. Thanks so much everyone! 💚


Comments

Popular posts from this blog

Hello World

Yosemite

Two Lines of Thought, Makes Me Wonder What I'm Missing