Created
July 29, 2015 08:33
-
-
Save alorence/b4e67a33264be496ad5f to your computer and use it in GitHub Desktop.
CheatSheet for some python synxtax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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