Basics Python 3 Review

As I said in my previous blog post I am taking a Machine Learning Course by the University of Washington on Coursera. The first segment a basic python review. I am accustomed with working with Python 2.7.  But I think it finally time to make that transition to Python 3. The only reason why I am doing it is because my mentor told me too. And it’s also becoming an industry standard In this post I am just going to go over some of the differences that I noticed in Python 3. If you want to see a more through review you can take a peak at my github page  Python Basics and Python Basics Continued 

The first difference between Python 3 and Python 2 is the print function.

python 2

  print "Hello Motto"

python 3

print("Hello Motto")

Another difference is Advanced String Formatting

python 2

i = 2
outLine ="Our float value is %s. Our int value is %s" % (f, i)

Python 3

username = 'mark'
password ='PApyaWhip'
"{0}'s password is {1}".format(username, password)

Another interesting function that I got to review again from the python introduction is the concept of Lambdas. I heard of them before when I started out learning python but I never quite got the concept. After teaching myself javascript and jquery this summer I have a better grasp of the concept of an anonymous function. An anonymous function is a function that was declared without any named  to call to it.  To generalize, a lambda function is a function that takes any number of arguments  returns the value of a single expression. The beauty of lambdas/ anonymous function you can do things such as map, reduce and filter quickly

g = lambda x: x*2

same as

def square(x):
 return x*2

If you want to learn more about the basics of python you should check out Elizabeth Wickes’ Python Self Study Lesson Plan

To learn more about lambdas

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s