Skip to content
Advertisement

Tag: string

Use index() to find multiple identical strings in Python

I have a string. The letter ‘o’ appears twice in the whole string, but when I try to use the index() function to locate the position where the ‘o’ appears, it just traverses from left to right and stops when it finds the first ‘o’. Why can’t index() print all the locations of ‘o’? If possible, how can I use

int unexpectedly turning into string

With the following snippet from a script: I expected the outcome to be: but instead I get: Does anyone know why this is happening and how I can fix it? In case you need it here is SelectTile: Answer You are not assigning the new int value to the original variable. Here’s a fix:

Python variable file path and string prefixes

Using tkinter to select output folder for processed files. Would like to use file_output and x as variables for my file path, My attempt: This does not work in my program. The output I need is I am reading the docs https://docs.python.org/3/reference/lexical_analysis.html#grammar-token-stringprefix Still don’t understand how to escape or a workaround, Help would be much appreciated. Answer you can easily

Why .join() didn’t work properly? (Python)

The code excludes vowels from a string. The code works, and print() does the job, but I need to return the result. I tried .join() but it didn’t work: it returns only the first character in my case, because the return stops the loop. How can I overcome this? Answer Try correcting your indentation: You could also consider utilizing a

how to show only the first letter of an element of a string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 8 months ago. Improve this question I have a list of words i.e. [‘cat’, ‘dog’, ‘chicken’] and I want to replace all letters except the first

String Slicing in c# using intervals

In python there are ways that allow you to access the string using an interval(slicing): Example Get the characters from position 2 to position 5 (not included): Is there something similar in c#? Answer In C# 8.0 (or higher) you can use ranges, e.g Or on old c# versions, Substring: Finally, you can use Linq, but it’s overshoot here:

Advertisement