Path: blob/master/resources/student-resources/python-self-assessment.md
1904 views
Python Resource Guide
Below are links to some recommended resources that past Data Science students have found helpful when learning Python. There is no single "best" resource; instead, you should try out a few and then focus on the one that teaches Python in a way that you understand.
Codecademy's Python course: Good beginner material, including tons of in-browser exercises.
Dataquest: Uses interactive exercises to teach Python in the context of data science.
Google's Python Class: Slightly more advanced, and includes hours of useful lecture videos and downloadable exercises (with solutions).
Introduction to Python: A series of IPython notebooks that do a great job explaining core Python concepts and data structures.
Python for Informatics: A very beginner-oriented book, with associated slides and videos.
A Crash Course in Python for Scientists: Read through the Overview section for a very quick introduction to Python.
Python 2.7 Quick Reference: A beginner-oriented guide that demonstrates Python concepts through short, well-commented examples.
Python Tutor: Allows you to visualize the execution of Python code.
Python Self-Assessment: Questions
How do you create an empty list named "mylist"?
What will the following code return?
5 > 3 or 5 < 3
What will be stored in the "nums" object?
nums = range(10)
How do you check the type and the length of the "nums" object?
How do you return the last number in the "nums" object?
Slice the "nums" object to return a list with the numbers 2, 3, 4.
What is the difference between
nums.append(10)
andnums + [10]
?How do you divide 3 by 2 and get a result of 1.5?
Import the "math" module, and then use its "sqrt" function to calculate the square root of 1089.
What type of object is created by this code?
d = {'a':10, 'b':20, 'c':30}
In the "d" object, what are "a", "b", and "c" called? What are 10, 20, and 30 called?
How do you return the 10 from the "d" object?
How do you change the 30 to a 40 in the "d" object?
From the "people" object, return Brandon's state only:
people = {'Alice': ['Washington', 'DC'], 'Brandon': ['Arlington', 'VA']}
Define a function "calc" that takes two variables, "a" and "b", and returns their sum.
SPOILER ALERT
DON'T REVIEW UNTIL YOU'VE COMPLETED THE SELF-ASSESSMENT
mylist = []
ormylist = list()
True
A list of the integers 0 through 9
type(nums)
andlen(nums)
nums[9]
ornums[-1]
nums[2:5]
nums.append(10)
modifies the original list, whereasnums + [10]
does not actually modify the list.In Python 3:
3/2
. In Python 2:3/float(2)
or3/2.0
.
import math
and thenmath.sqrt(1089)
. Alternatively,from math import sqrt
and thensqrt(1089)
.A dictionary
"a", "b", and "c" are the keys, and 10, 20, and 30 are the values.
d['a']
d['c'] = 40
people['Brandon'][1]
def calc(a, b): return a + b
(usually written as two separate lines)