Home > Articles > Programming > Python

  • Print
  • + Share This
This chapter is from the book

Q&A

  • Q. Is there any way to see all of the things I can do with a string without looking it up online?

  • A. If you want to see everything you can do with strings, type this into your Python shell:

    >>> s = ""
    >>> help(type(s))

    A list of everything you can do with strings will pop up. Pressing Enter will move you down one line, your up arrow will move you up one line, spacebar will move you down one page, and “q” will close the help menu. Note that this behavior is slightly different in IDLE, where all the text is printed at once.

    Incidentally, you can get this screen with any kind of Python data type. If you wanted to find out all the methods that come with the integer type, you could do something like this:

    >>> s = 1
    >>> help(type(s))
  • Q. Why are the methods to remove whitespace from the beginning and end of a string called “right strip” and “left strip”? Why not “beginning” and “end”?

  • A. In quite a few languages, text isn’t printed from left to right. Arabic and Hebrew are both written from right to left, whereas many Eastern scripts are written from top to bottom. “Right” and “left” are more universal than “beginning” and “end”.

  • Q. How big can a string be?

  • A. That depends on how much memory and hard drive space your computer has. Some languages limit the size of a string, but Python has no hard limit. In theory, one string in your program could fill up your whole hard drive!

  • + Share This
  • 🔖 Save To Your Account