Skip to content

Instantly share code, notes, and snippets.

@alorence
Created July 29, 2015 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alorence/b4e67a33264be496ad5f to your computer and use it in GitHub Desktop.
Save alorence/b4e67a33264be496ad5f to your computer and use it in GitHub Desktop.
CheatSheet for some python synxtax
s = 'abcdefghij'
stmts = [
'len(s)',
's[0]',
's[1]',
's[0:]',
's[1:]',
's[0:3]',
's[:3]',
's[:-2]',
's[:-3]',
's[:-4]',
's[-3:]',
's[0:len(s)]',
's[0:len(s)-1]',
's[0:4]',
's[1:5]',
's[2:6]',
]
print('s = %s' % s)
print('-' * (len(s) + 4))
for stmt in stmts:
print('%s = %s' % (stmt, eval(stmt)))
print('-' * 20)
for i in reversed(range(len(s))):
for j in range(len(s) - i):
part = s[j:i+1]
print(part)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment