This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Tuesday, September 15, 2015

CHPC Python Tutorial

Python Style Guide:

http://legacy.python.org/dev/peps/pep-0008/

Python Lectures:
https://gitlab.chpc.utah.edu/u0253283/Python-Lectures


Converting tuple to a list

>>a = (1,2,3,4)  # this is a tuple
>>
>>c = list(a)      # this will convert the tuple to a list
>>
>>type(c)
List
>>print c
[1,2,3,4]


String output, this is good for concatenating strings with variable names with numbers. Use this for plot titles and such rather than using the '+' indicator

print('print the numbers in this string here: {0}, here {1}, and here {2}.'.format(8,7,6))

As opposed to:
print 'print the numbers in this string here: ' +str(8)+', here '+ star(7)+', and here '+ str(s)+'.'


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.