I am paid to write programs and have been since 1979 including programming python the standard template I use when starting a new program is _________________________________________________________________ def run(): # do stuff here if __name__ == '__main__': run() _______________________________________________________________________ I suggest you do the same Python programs consist of modules. A module is a .py file (more or less) A lot of python is written in python as modules so you standard template might easily become _________________________________________________________________ import os import sys def run(): # do stuff here if __name__ == '__main__': run() _______________________________________________________________________ the reason for the if __name__ == '__main__': run() is the variable __name__ is set to '__main__' if, and only if, the module is invoked from the command line python my_module.py it is possible to have code in a python file not in a function e.g. _________________________________________________________________ print(' this message will be printed out whenever this module is loaded') _________________________________________________________________________ the if __name__ == '__main__' is to ensure that the code is only run if it's in the main module (i.e. the one mentioned on the command line) functions enable your program to be split into small chunks ideally each function should do a single task this makes it easier to understand and check that it is right in addition your function may be used by many different python programs (e.g. read a file) Besides functions there are 2 main programming things (constructs) Loops and if/elif/else loops allow a piece of code to be repeated over and over, while something changes the 2 main mechanisms for loops in python are while and for while : statements a is some logically test which might be as simple as True which is always true or something like i < 10 e.g. i = 0 while i < 10: print(i) i = i + 1 this will print out the numbers 0 to 9 a very common mistake in such a loop is to miss out i = i + 1 so the loop goes on for ever there is an easier way to code this in python for i in range(10): print(i) here range ensures that i is set from 0 to 9 in steps of 1 range takes up to three parameters 2 being optional range( [start], stop, [step]) so to go from 1 to 11 in steps of 2 range(1, 12, 2) # remember in python the end limit is 1 passed where you want to stop Comments # any character after a # is ignored until the start of a new line Types Python has different 'types' for data '1' is a string which holds the character 1 'hello samuel' is a longer string 1 is an integer. Integers are whole numbers 1.0 is a float i.e. a decimal numbers in python you create variables by assigning them a value e.g. my_age = 62 my_first_name = 'Humperdink' unlike languages like java or c++ you do not have to specify the type of variables in advance AND the type of a variable can change just by assigning something different to it my_age = 62 # type of my_age is integer my_age = 'little jim' # type of my_age is now string Classes Enable you to create new types but that is for another day Collections the main collections in pythons are lists and dictionaries a list is a collection of things, which can be all different types, though often not If you read a file it is common to get a list of strings each 'element' in the list is a single line of the file. a dictionary is a collection of key value pairs e.g. my_dict = { 'samuel' : 'Samuel Shiers', 'alex : 'Alexandra Shiers, 'becca' : 'Rebecca Shiers' } you can test if a key exists in a dictionary test_key = 'ethel' if test_key in my_dict: print(my_dict[test_key]) else: print('{0} not in my_dict'.format(test_key) Really there are 2 parts in learning to program 1) practicing using building blocks (ie doodles) such as reading a file 2) when trying to write a problem seeing how the problem can be broken into building blocks and how these building blocks can be bolted together to make a program which solves the problem