Skip to content
Advertisement

Tag: string

str method not printing correctly

I’m working on creating a subclass Rug from a parent class rectangle for school. Everything looks like it should be working but when I try to print the __str__ method for the subclass the only that populates from the parent class is <__main__.Rug object at 0x0000019C2B69C400>. This is my Parent Class : This is my Rug subclass : This is

Python split function behaviour

returns This behaviour seems really strange to me. Why are blanks returned only for b and not a? Answer As was pointed out by others, the documented behavior of str.split explains your results. Since you specify sep to be ‘)’, split looks for the strings that surround it, and in the case of ‘)’, finds exactly 2 empty strings (not

How to Redirect URLs to a certain URL Django Regex

In my URLs.py, I’m setting my URL like this Navigating to localhost:8000/mobile works as expected but if typed in the URL: localhost:8000/mobile/hello/world/234234hjhf8sc3 it should redirect to localhost:8000/mobile however this does not happen because my regex is incorrect (I’m not sure) How could I do this/what is the correct regex to do this? Another example would be localhost:8000/mobile/send/help/as792lp should redirect to

Given a list of binary numbers (0s and 1s), determine the number of possible arrangements of distinct binary sequences using given 0s and 1s

Given a list of binary numbers (0s and 1s), determine the number of possible arrangements of distinct binary sequences using given 0s and 1s. Input Format: A single line of input containing 0s and 1s Output Format: Print an integer value indicating the number of possible arrangements using given 0s and 1s Example: Input: 0 1 0 1 Output: 6

compare list elment to a string

I have the following list and the following string I want to check if any element in the list is in the string I tried using however it gives false seems python can’t recognize the element in the string, is there a way to check elements from list to a string if there is a match. i did it successfully

Getting TypeError: ‘str’ object is not callable in my script

while running this program I am getting the error “TypeError: ‘str’ object is not callable”. Any ideas? Answer There are a couple of problems with the posted code. First, the call to caesar_encrpyt() needs to look like caesar_encrypt(s, step). Secondly, you have two local variables in that function defined as i; that one that’s being returned should be changed to

validation-remove currency symbol from price

I have this one string, which is actually price, this price value comes with any currency symbol (currency_list), I am trying to remove these currency symbols from price and return only price. Till now I am able to do it for prefix and suffix currency symbol using below code , everything works till here. I just want to add one

How to remove str. Of spaces from list [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 1 year ago. Improve this question A = [“a”,”b”,” “,”c”,” “,”d”] How can I remove str. Of white spaces

Translating python raw string / regex to ruby

I’m currently trying to translate a python script to ruby. Now I’m stuck on a part that uses a raw string for a regex. This is the original python code: This is my attempt to translate it to ruby: Unfortunately I must be doing it wrong because I get this error: I also tried: But it results in the same

Advertisement