← back to writing

Python: Strings

I liked that it started with the string data type

I don't remember any course I've taken that started variables and data types with strings in particular.

tem que ter uma imagem aqui

Well, what I've learned:

Strings

From C, I've learned that strings are an array of characters.

Python's strings the book define them as a series of characters, with Python considering anything inside quotes as a string. Either single or double quotes.

Then I've learned some methods, and I've found particularly interesting that the book started this way. I think that this approach is more reasonable, easy, and thorough at the same time.

Methods learned

.upper() - takes all characters of a string and turns them uppercase.

.lower() - takes all characters of a string and turns them lowercase.

.title() - takes all characters of a string and turns them lowercase, then take every character that comes first in a word and turns it uppercase.

.removeprefix() - to remove prefixes, e.g.:

    url = "https://dcalves.com"
    print(f"{url.removeprefix("https://)})
    # prints to console dcalves.com, without
    # the https:// prefix.

.removesuffix() - does the same, but at the end.

How could I forget about strip?

.rstrip() - removes trailing whitespace at the end of a string.

.lstrip() - removes trailing whitespace at the beginning of a string.

.strip() - removes trailing whitespace at the beginning & end of a string.

f-strings

I've already familiarised myself with f-strings, particularly with Rust's macro print! and println!, and C's printf

So, in that topic, nothing was particularly new to me.

Rust's syntax of f-strings already employ {} and \n, etc.

On C, I believe there is no {} syntax, it goes something like %v.

Also Go, fmt.Printf. I've read Go's documentation one day, to decide if I should start by learning Go or Python (Python it is, here we are!).

The exercises where great.

And also, my AI servant Claude assisted me in structuring my projects and learning python directory.


Still no word from anyone, but the voices on my head told me, since I already have a domain registered, this dcalves.com, I should at least link it here to my gitlab.io.

Also, my OCD told me that Google standard user accounts are data mined, milked to the death, even if you pay Google One (which I did)

So I transitioned to Google Workspace, which follow company-tightened rules and legal standards. Now I am the customer, not the product.