Example
String Methods - upper, lower, strip
Useful methods for working with text: changing case, removing whitespace.
Showing 1–10 of 24
Example
Useful methods for working with text: changing case, removing whitespace.
Challenge
Turn " Launch " into launch with strip() and lower(), check it against the command list, then accept underscores and dashes too, so commands match however operators type them.
Challenge
…for the analogue mission: trim and capitalise names, lower-case emails, then reject sign-ups with no name or a broken email and drop duplicates by email, saying why for each one.
Challenge
…names like de Vries and van Dijk correctly with key=str.lower.
Challenge
…them, and safe, so they work on every operating system: lower case, no spaces, the sensor first and then the date. Build the file names from the data, then a folder path for each sensor. From an ID…
Challenge
…: Starting the sequence Normalise the answer with strip().lower() straight away, then compare it in an if / elif chain, with else at the end. Helpful errors Make the errors helpful. For an empty…
Challenge
…command: dance REJECTED "": empty command text.strip().lower().split() gives the words. Converting the length can raise its own ValueError : catch it and raise yours, with a clearer message. set mode…
Challenge
…From 400 °C it's WARN, from 450 °C CRITICAL, anything lower is OK. For 412.5: WARN Check the most serious level first: if for CRITICAL, elif for WARN, else for OK. "From 400" includes 400 itself, so…
Challenge
…what crate[1:] gives, as text, in rest . Then put crate.lower() on a line of its own, print crate , and store whether it is still "P0042" , True or False , in unchanged . Remove the lines you added…
Article Mini projects
…= 1 quick_dispenser.max_daily_doses = 3 # Lower limit for testing for i in range(5): result = quick_dispenser.request_dose() print(f"Dose attempt {i+1}: {result}") if i < 4: # Don't wait after last…