Learning a New Language: Python

Trayshawn Webb
4 min readMay 16, 2021

--

I’m starting my journey to learn about machine learning and with that I’m learning a new language. Python is one of the primary programming languages used for machine learning, which is part of the reason I chose it. Python is also a very popular programming language in general. Since I’m still fresh in my programming journey, I think it’s good first language to learn by myself outside of school.

I haven’t been able to delve deep into it but I did start with the basics to give me a general understanding. The first thing I started with was variable assignment, which is a common characteristic in all the programming languages that I’m familiar with. Variable assignment in Python is very similar to Ruby, primarily because you don’t need to declare the variable with something like a let, var, or const in JavaScript. For example, if I want to create an author variable for the author of this blog, I just simply put author = “Trayshawn” — strings must always be in quotes. You can also add variables together. So, if I wanted to create another variable, author_last_name = “Webb” and combine it with with author and an empty space in the middle, I would get Trayshawn Webb. For clarity, author + “ ”+ author_last_name = “Trayshawn Webb.” That’s kinda the same in most programming languages, so I know it doesn’t blow your mind away. However, one of the cooler things about variable assignment in Python is you can list variables and set that list equal to another list of values and it’ll automatically assign the variable to the respective value. x,y,z = 1,2,3 means x will equal 1, y equals 2, and z equals 3.

Speaking of lists, I also worked on the basics of lists, which are called arrays in the programming languages, and tuples in Python. Most everything about the lists are similar to how arrays behave in other programming languages, but Python does have some cool attributes, which help me to understand why it’s the language of choice for most data scientist. You can “slice and dice” — my choice of words — arrays without using special functions. You can use a colon to select pieces of the array that you want; array[3:6] will return the values in the array from the 3rd index to the 6th index, non-inclusive of the 6th index, assuming the array has all of those indexes. Similarly, you can do array[:3] or array[3:], and you’ll get the values in the array from the beginning to the third index and the third index index to the last value respectively, inclusive of all values. Tuples are like a combination arrays and variable assignment but not really. Tuples are a collection of data which is ordered and unchangeable, written with parenthesis. For example, (x_values, y_values) = ([1,2,3],[-1,-2,-3]); the x_values equals the positive integers and y_values equals the negative integers.

You can use indexing to get the specific values in the x or y values, which can then be used to plot points on a graph using x and y coordinates from the values.

Now that I had a solid understanding of object and data types in Python, it was time to move to functions, conditionals, and loops. Functions are also similar to how they operate in ruby, so you can declare them with a “def” and function name follow by arguments in parenthesis if it takes any, then use a colon to close out defining the function name, press enter and then put what the function does. You hit enter again and the function is defined. You don’t have to type “end” to end the function, it just knows based on the empty space. The same is true for conditionals, they behave the same in ruby, but you end the conditional with a colon. Loops are similar but they’re slightly cooler, because you can just do for “i” in a range or list and it’ll loop through it. You see that here in for and while loops:

The last of the basics that I practiced with is modules, which behave similar to components in React. You just import the module you need and use the functions or import specific functions from the whole module. For example, the math module comes with a lot of math functions, such as power and square root. The modules will play a crucial part in my learning and using machine learning.

With the basics of python out of the way, I can know move on to the some of the more complicated pieces of machine learning.

--

--

Trayshawn Webb
Trayshawn Webb

Written by Trayshawn Webb

0 Followers

New Orleans native and Universal man still learning, still growing.