Questions for students to consider:
1) What happens when you get a new dataset that you need to analyze in the same way you analyzed a previous data set?
2) What processes do you do often? How do you implement these?
3) Do you have a clear workflow you could replicate?
4) Or even better, could you plug this new data set into your old workflow?
-
Learning Objective: Employ best practices of naming a variable including: don’t use existing function names, avoid periods in names, don’t use numbers at the beginning of a variable name
References: https://www.tutorialspoint.com/python3/python_variable_types.htm
In [9]:
# write out three variables, assign a number, string, list
x = 'Asia' # String
y = 1952 # an integer
z = 1.5 # a floating point number
cal_1 = y * z
print cal_1
# or
x, y = 'Asia', 'Africa'
w = x
w = x + x #concatinating strings (combinging strings)
print w
h = 'Africa'
list_1 = ['Asia', 'Africa', 'Europe'] # list
print list_1
In [ ]:
# Questions for students:
# 1) what do you think will happen with this code? x * z
# 2) what do you think will happen with this code? list_1[0]
# 3) what do you think will happen with this code? list_1[1:2]
In [ ]:
list_1 # this is not a very descriptive and identifiable variable
countries = ['Asia', 'Africa', 'Europe']
global vs. local in functions
Global variables are available in the environment your script is working in. Every variable we have made at this point is a global variable.
Local variables will be useful to understand when we start using functions in the automation of our code. Local variables only exist in the function environment, not the global environment your linear workflow code is.
1) set-up variables at the begining of your page, after importing libraries 2) use variables instead of file names, or exact values or strings so that if you need to change the value of something you don't have to search through all your code to make sure you made the change everywhere, simply change the value of the variable at the top. -- This will also make your code more reproducible in the end.
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: