Learning A New Language: Python Part 1

Madeline Stalter
4 min readMar 10, 2021

The acquisition of Python appears to be a “no-brainer” in terms of desired skills in the marketplace today. Python is exciting as it can be leveraged for a multitude of purposes: web development, data science, and machine learning. Python is a high-level programming language that is designed to be readable and efficient in terms of lines of code used. Its core, user-friendly approach reminds me a lot of Ruby — a language that I already know and love!

Source: https://stackify.com/wp-content/uploads/2019/01/Ruby-vs-Python-1280x720.jpg

1. Variables

In theme with the praise of Python above, defining and setting variables is very easy!

2. Conditional Statements

In Python, we use the if keyword to evaluate whether a statement is true or false. If true, then the program will execute the contained code block.

We can incorporate the else keyword to capture what happens if the statement evaluates to false.

The elif keyword can be used to check for more cases as well.

3. Iteration (Looping)

The while and for loop are most helpful in Python. The while loop dictates that while the state is true, execute the code block.

The for loop dictates that for x, execute the code block.

4. Lists

Lists allow us to store collections, or lists, of data. For example:

To get a specific value from a list, we can leverage the element’s index. The index starts with 0.

There are methods to manipulate lists; some of which include:

5. Dictionary: Key-Value Pairs

In lieu of using numbers as indices, we have the dictionary data structure that is comprised of key-value pairs (the keys can be of any type — numeric or string).

6. Classes & Objects

Similar to Ruby, objects are meant to represent the real world. Objects contain data (or attributes) and have behavior (or methods that can be preformed on them to accomplish some task). A class is the blueprint from which individual objects are instantiated; or in other words, classes define the attributes and behaviors that objects have. The class syntax is as follows:

Here sidney is an object (or instance) of the Dog class. In order to set attributes of sidney, we will define our class to receive data when an object is initiated.

You can reassign the values of attributes as such:

7. Non-Public Instance Variables

Non-public instance variables can be accessed and updated; however, they’re considered a non-public part of the API. We define non-public instance variable using a _ before the variable name; methods work in the same fashion.

8. Class Inheritance

Classes can inherit from parent classes! For example:

--

--