11 Matching Annotations
  1. Apr 2025
    1. Method Parameters Description upper none Returns a string in all uppercase lower none Returns a string in all lowercase capitalize none Returns a string with first character capitalized, the rest lower strip none Returns a string with the leading and trailing whitespace removed lstrip none Returns a string with the leading whitespace removed rstrip none Returns a string with the trailing whitespace removed count item Returns the number of occurrences of item replace old, new Replaces all occurrences of old substring with new center width Returns a string centered in a field of width spaces ljust width Returns a string left justified in a field of width spaces rjust width Returns a string right justified in a field of width spaces find item Returns the leftmost index where the substring item is found, or -1 if not found rfind item Returns the rightmost index where the substring item is found, or -1 if not found index item Like find except causes a runtime error if item is not found rindex item Like rfind except causes a runtime error if item is not found

      All good things to remember and come back to!

    1. Our definition was simple: a string is simply some characters inside quotes. In this chapter we explore strings in much more detail.

      A string is simply some characters inside of quotes.

    1. it’s also likely that it will be on the right hand side of an assignment statement, or as a parameter to a function

      Most errors happen on the right-hand side of the expression.

    2. Finding Clues One thing that can help you in this situation is to print out the values and the types of the variables involved in the statement that is causing the error.

      Print out or write down the values and the types of the variables involved in the statements.

    3. This is lesson three and is one of the most common errors we see in introductory programming. What is the difference between int(x) and x = int(x) The expression int(x) converts the string referenced by x to an integer but it does not store it anywhere. It is very common to assume that int(x) somehow changes x itself, as that is what you are intending! The thing that makes this very tricky is that int(x) is a valid expression, so it doesn’t cause any kind of error, but rather the error happens later on in the program. The assignment statement x = int(x) is very different. Again, the int(x) expression converts the string referenced by x to an integer, but this time it also changes what x references so that x now refers to the integer value returned by the int function. So, the solution to this problem is to change lines 3 and 4 so they are assignment statements.

      One of the most COMMON ERRORS!!!

    4. Notice that on line 2 the function imt is not highlighted blue like the word int on line 4.

      Yeah it is or I'm blind.

    5. If you follow the same advice as for the last problem, comment out line one, you will immediately get a different error message.

      Commenting out or commenting on a line stops the code from executing, it's like a way to disable the code and leave notes for yourself.

    6. t’s also important to keep calm, and evaluate each new clue carefully so you don’t waste time chasing problems that are not really there.

      Keep calm and reassess the code before making any big changes.

    7. Aha! Now we have an error message that might be useful. The name error tells us that wait_time_int is not defined. It also tells us that the error is on line 5. That’s really useful information. Now look at line five and you will see that wait_time_int is used on both the left and the right hand side of the assignment statement.

      It should be (wait_time_str) like the second row, not (int) because its not recognized. It also does not have value so it cannot be used on the right hand side.

    1. concatenated

      linked together.

    2. But if you entered 17 (5 pm) for current_time and 9 for wait_time then the result of 26 is not correct. This illustrates an important aspect of testing: it is important to test your code on a range of inputs. It is especially important to test your code on boundary conditions.

      Always test you code with multiple inputs as it may not work for all inputs. You need to be able to determine the range and figure out what input works best for the solutions.