Skip to content

Instantly share code, notes, and snippets.

@miura
Created March 21, 2014 14:31
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 miura/9687511 to your computer and use it in GitHub Desktop.
Save miura/9687511 to your computer and use it in GitHub Desktop.
a = 1
b = 2
c = a + b
print c
a = '1'
b = '2'
c = a + b
print c
def addition(x, y):
z = x + y
return z
d = addition(a, b)
print d
#Creating a list
l = [8, 7, 100, 1]
print l
print l[0] #specify index
print l[2] #specify index
print len(l) # length of the list
print sorted(l) #sorting the list
#Creating a list with evenly spaced elements
# 10 elements
ll = range(10)
print ll
#the last index
print ll[len(ll)-1]
#secify a range (slicing)
print ll[1:3]
# check what happens
ll = range(10, 20)
print ll
ll = range(10, 20, 2)
#append a value
ll.append(1000)
print ll
#concatenate lists
lll = l + ll
print lll
l = [8, 7, 100, 1]
for a in l:
print a
for b in range(10):
print b
l = ['abc', 'efg', 'hij']
for b in l:
print b
for i, b in enumerate(l):
print i, b
a = 1
b = 2
if a == b: # 'equal to'
print 'same'
if a != b: # 'not equal to'
print 'different'
# combined
if a == b:
print 'same'
else:
print 'different'
a= 1
b= 2
print a == b
print a != b
if True:
print 'prints always'
if False:
print 'never prints'
else:
print 'always printed'
#String
file1 = 'data.tif'
file2 = 'data.jpg'
print file1.endswith('.jpg')
print file1.endswith('.tif')
print file2.endswith('.tif')
print len(file1)
print file1[4:6]
file1 = 'data.tif'
def checkJPG(fname):
if fname.endswith('jpg'):
return True
else:
return False
print 'jpg file:', checkJPG(file1)
#Dictionary, key-value pairs
dd = {'vsvg':'abc.tif', 'pm':'cde.tif', 'dapi':'efg.tif'}
print dd['vsvg']
print dd['dapi']
print dd.keys()
print dd.values()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment