Thank you for visiting the Agora of Flancia!

This Agora is in active development. Please report bugs and send feedback!

Settings

Browse Agora as

If you notice any strangeness, try clearing your local storage or reach out for support at agora@flancia.org.

Joining this Agora

For now, some work is required 😇

With your digital garden

Please review this Agora's base contract to verify you are in agreement, then send email to signup@anagora.org with the following information:

  • The URL of a Git repository containing your digital garden, wiki or blog; or of the content you would like to contribute.
  • Your desired username (you can check for existing users here).
Please also reach out if you are interested in joining but need clarification or assistance. We are working on making this process less manual and more user friendly and inclusive :) Thank you for your patience!

From social media or chat

You can contribute:
  • From the Fediverse by following and interacting with @agora@botsin.space.
  • From Bluesky by following and interacting with anagora.bsky.social.
  • From Matrix by adding @anagora:matrix.org to a room.
You search for 'Python String Operations' on the Internet x
🔍 Web results by GoogleBingDDGMarginaliaYouTubeMapsYouTube Music BlueskyFediverseX ⬈
Some providers may not allow embedding. If a tab appears empty, you can use the link in the header to open the search in a new tab. x
🤖 AI generations by MistralGeminiChatGPT ⬈Claude ⬈
This is an Agora Assistant trying to help you navigate generated by the provider above. x
Loading Wikimedia Commons...

Loading Wikimedia content...


This you find in the Agora of Flancia x
📚 Node python string operations exact match
Nodes contain individual contributions whose filenames match your search. x

Python String Operations

Go to thePython Week 1 Main Page or the Python - Main Page Also see the Programming Main Page or the Main AI Page

Strings are ordered lists of characters, whether they be letters, numbers, spaces, or special characters.

Indexing

Individual elements in a string can be accessed like an index in an array. This has been referred to in other places as slicing and subscripting.

string_var = "Kieran"
print(string_var[3])
>>> r

A visual representation of a string as an array with an index

While we can access invidual elements going forward from zero, we can use negative indexing going backward from -1 at the last position to access each element as well.

string_var = "Kieran"
print(string_var[-1])
>>> n

I love negative indexing.

Stride

You can also step through the elements of the string at a certain number of elements per stride.

string_var = "Kieran Bicheno"
print(string_var[::2])  # Here the stride is 2, or every 2nd character, first-inclusive
>>> Kea Bceo

A visual representation of both stride and slicing

Slicing

We can assign parts of a string to another variable by slicing it using the index notation. In the code below, the first number is where we start the second number is where we stop including elements and the third number is the stride

string_var = "Kieran Bicheno"
new_string = string_var[0:7:2]
print(new_string)
>>> Kea B

To be clear

In the code [x:y:z]

  • x —> The first element we include
  • y —> The first element we do not include
  • z —> The stride, which is first-element inclusive

String Functions

len() gives the length of a string + concatenates strings * repeats a string \ is an escape sequence \t is a tab \\ is a backslash

Placing an r in front of a string in a print statement automatically escapes the string.

print(r"I can use a \ in this string because of the r at the front.")

An illustration of using r in a print function. This has been bugging me.

String Methods

Strings are special in that they have both the generic set of Sequence Methods but also their own String Methods

Methods create a new variable

So when I call string_var.upper(), I need to assign the value to a new variable, I can’t just do it "in place."

For example:

string_var = "Kieran Bicheno"
string_var.upper() # This line either does nothing or throws an error
new_string = string_var.upper()
print(new_string)
>>> KIERAN BICHENO
⥱ Context for python string operations
💬 Stoas for Python String Operations
Stoas are shared spaces where interested people can meet and collaborate. x
Hypothes.is x
Agora Meditation x
Ambient Music x

Now playing...