Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
as I learn in my college in programming concept language course
the string length in any language may be one of three:
Static: as COBOL, Java’s String class
Limited Dynamic Length:as C and C++
In these languages, a special character is used to indicate the end of a string’s characters, rather than maintaining the length
Dynamic (no maximum): SNOBOL4, Perl, JavaScript
What of these options python string length are?
Python strings are immutable. Any operation that appears to be changing a string's length is actually returning a new string.
Definately not your third option -- a string can start out arbitrary long but can't later change it's length. Your option 1 sounds closest.
You may find the Strings subsection of this web page helpful. Even in a language where strings can, in general, change length, that may not be true of all strings, depending on where they originate (e.g. code text) or how they are declared.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I want to detect and/or replace weird utf, non-emoji characters that break my tokenization pipeline, like \uf0fc, which renders like a cup/glass:
That image / code is not contained in the emojis package, which I tried for filtering.
Is there a class that describes all such characters?
Is there a way I can reliably detect them?
This is a character from a Private Use Area. It happens to look like a tankard in your font, but the Unicode standard doesn't mandate a specific look or meaning for these; it has whatever meaning you assign to it. The idea is that you agree upon a meaning with whoever you're communicating with - privately, meaning without getting the Unicode Consortium involved.
You can use the standard unicodedata module to check whether a character is from the Co category, or just hardcode the ranges, as described here.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I personally couldn't think of anything, but I'm wondering if there are some edge cases, where an older method might be somehow better.
It is often better to do logging calls via
log.info("some log {} data {} to be logged", arg1, arg2)
# will be `message.format(*args)` at the end of the day
vs.
log.info(f"some log {arg1} data {arg2} to be logged")
The reason is that if my logger is not configured to log INFO logs then the the second snippet does a potentially expensive string interpolation, converts the arguments to strings, etc. The first snippet does not do the interpolation and returns early without serializing the arguments.
Yes, when you need to reuse the same template string in multiple ways is better to use formatted strings. For example take a look at this question
f-strings aren't an option for anything you want to be localizable. An f-string is hard-coded directly into your program's source code, so you can't dynamically swap it out for a translated template string based on the user's language settings.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm learning Python and I just found out about the capitalize method on strings. It capitalizes the first letter of a string, and only the first letter. It also converts all other characters in the string to lower case.
What scenario was this method designed for? I'm having a hard time imagining the need for a function that does this. It's possible that sometime in the last 20+ years of programming I have needed such a function, but if I have I don't recall it.
Capitalizing Names
One thing that comes to mind is the capitalization of names. But it's not true (in English, French and Spanish, at least) that all names (of people, places or anything else I can think of) start with a capital letter and all the other letters are lowercase. So that seems like at best a use case that supports only poor user experiences.
I want to know what the designers of the language had in mind when they created this method. That's not really opinion-based, although it may be impossible to know, unless they documented it. Have any of you read any documentation from the Python designers about use cases for this method?
I googled "python string capitalize method why would you need that" every way I could think of and didn't come up with any hits.
Please enlighten me!
It's for when you want to capitalize just the first letter of a string.
The standard library in python contains a huge amount of functionality that the average program will not require - but other programs find extremely handy. If the standard library only included functions that every program would use, then it would not be hailed for being the simple-to-use language that it is.
Imagine that you have a database (or even a csv) where you have told all your friends to fill in their first and last name. While doing so, some of them did not capitalize the first letter of their last name or first name. But when you want to print them on let's say "list of guests coming to your party", you want to consistently print first letter of their first and last name irrespective of their input, because it's a general norm.
In this situation, you just use capitalize() over firstname and lastname of your csv. Silly analogy though!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a keyword:
Verify Payment Method Field
Element Text Should Be ${paymentMethodValueField} PDF-lasku sähköpostiin
here is the logs:
Step 3 Fields verification :: OK: Display Customer Information fie... | FAIL |
The text of element '//div/span' should have been 'PDF-lasku s?hk?postiin' but in fact it was 'PDF-lasku s?hk?postiin'.
I need to write something like that, but I don't know how:
PDF-lasku s[ascii symbol]hk[ascii symbol]postiin
can somebody help me?
I would probably convert the whole thing to one format or another, then evaluate? Or is it important that ASCII characters are located in certain parts of the string? If not and you simply want to verify what is returned is exactly what you expect, I'd probably use Encode String to Bytes for simplicity, perhaps even the encoding/decoding keyword would serve your needs if the ASCII is important.
http://robotframework.org/robotframework/latest/libraries/String.html#Encode%20String%20To%20Bytes
By using the above you could set it to ignore the characters that cannot be converted or replace them with a known character that you provide. Simply get the text first, then perform whatever manipulation you want and evaluate.
The alternative with regard to decoding/encoding if ASCII location is important is:
http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Convert%20To%20Bytes
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to sort the letters in a string alphabetically in Python without using join()? Using join() we can do this:
def sort_string(a)
return ''.join(sorted(a))
Is there a way to sort string without using join()?
Your solution is correct as strings are immutable in python. So, it's impossible to change (in your case - sort) an existing string. You have to create new one (you do it with join() call).
Also, good notes about sorting letters in string in python can be found here: How to sort the letters in a string alphabetically in Python