Strings

  • Strings are anything within 'single quotes', "double quotes", """triple quotes""" of a combination of quotes such as "'python2.7.2'"

In [1]: s="Python is named after the British comedy skit Monty Python"

In [2]: s[0]
Out[2]: 'P'

In [3]: s[0:6]
Out[3]: 'Python'

In [4]: s[0:6:2]
Out[4]: 'Pto'

In [5]: s[-1]
Out[5]: 'n'

In [6]: s[::-1]
Out[6]: 'nohtyP ytnoM tiks ydemoc hsitirB eht retfa deman si nohtyP'

In [7]: s.upper()
Out[7]: 'PYTHON IS NAMED AFTER THE BRITISH COMEDY SKIT MONTY PYTHON'

In [8]: s.lower()
Out[8]: 'python is named after the british comedy skit monty python'

In [9]: s.(tab)
s.capitalize  s.endswith    s.isalnum     s.istitle     s.lstrip      s.rjust       s.splitlines  s.translate   
s.center      s.expandtabs  s.isalpha     s.isupper     s.partition   s.rpartition  s.startswith  s.upper       
s.count       s.find        s.isdigit     s.join        s.replace     s.rsplit      s.strip       s.zfill       
s.decode      s.format      s.islower     s.ljust       s.rfind       s.rstrip      s.swapcase    
s.encode      s.index       s.isspace     s.lower       s.rindex      s.split       s.title       

In [10]: help(s.islower)
Help on built-in function islower:

islower(...) method of builtins.str instance
    S.islower() -> bool
    
    Return True if all cased characters in S are lowercase and there is
    at least one cased character in S, False otherwise.

In [11]: s.islower()
Out[11]: False

Last updated

Massachusetts Institute of Technology