Programming Tutorials

  • View all tutorials
  • Common Python string methods
    Below are some string functions that are commonly required in order to complete Coderbyte challenges. You can view a longer list of Python string functions at the following links: Tutorialspoint Guru99


    Count how many times a character sequence occurs in a string. s = "hello world I am coding" print s.count('o') # 3


    Find the index at which the string appears in the original string. s = "hello world I am coding" print s.find('world') # 6 print s.find('mars') # -1

    isalpha and isdigit

    Determine if the string is alphabetic or if it is a digit. s = "hello" n = "456" print s.isalpha() # True print s.isdigit() # False print n.isdigit() # True


    Replace a part of a string with another string. s = "hello world" print s.replace('world', 'mars') # hello mars


    Swap all uppercase and lowercase characters. s = "HeLLO WORLD" print s.swapcase() #hEllo world


    Capitalize the first letter of each word. s = "hello world i am coding" print s.title() # Hello World I Am Coding


    Join a list of strings into one string separated by the input string. nums = ['dan', 'mike', 'rob'] print ' '.join(nums) # dan mike rob print '-'.join(nums) # dan-mike-rob

    upper and lower

    Uppercase or lowercase a string. s = "hello WORLD" print s.upper() # HELLO WORLD print s.lower() # hello world
    mrdaniel wrote this tutorial on 1/3/16 | python, strings
  • +
  • 10
  • -
  • Thanks for the useful tutorials and STEP by STEP guide.
  • +
  • 0
  • -
  • I'd recommend beginners to Python's official website (e.g. rather than the suggested links. Learning a new programming language often requires details that may have been overlooked in such tutorials.
  • +
  • 0
  • -
  • Thank you!
    Log in to submit a comment.