Learning a New Language
Tags: python, codenewbie
Published: 2019-09-19 19:04:22

As a recent graduate of the Flatiron School's Web Development program, I have spent the past 4 months working with Ruby and JavaScript. I have been exposed to other languages in some capacity before but I had not tried to learn a new language and framework on my own.

## Why Python?

![](https://images.freeimages.com/images/large-previews/5eb/green-tree-python-1312700.jpg)

I was on the fence about a new language and decided (for better or worse) to go with a dynamically typed language rather than something like Java which is statically typed. My main interest was to learn a new language that was strongly typed as a change from JavaScript which I have been focusing on heavily for the past couple months.

### Brief aside on typed languages

For the purposes of understanding the differences between static and dynamically typed languages all you need to understand is that static languages are more strict and do not allow types to be mutated. Furthermore, strongly typed in this scenario is referring to type errors being prevented at runtime. This basically means that instead of returning undefined like in JavaScript, I would receive an error if I was using incorrect types in Python.

## Python Initial Response

![](https://images.freeimages.com/images/large-previews/c1c/dog-1361477.jpg)

Once I got started with Python, I noticed a few things that I liked immediately. List, Dictionary, Set, and Generator comprehensions are things that I very much enjoy using. Although in a general sense it is basically just a way to iterate over these structures, their syntax is very enticing to me. Let's just use a brief example here.

```python
new_list = [1, 2, 3, 4, 5]
new_list = [num for num in new_list if num % 2 == 0]
print(new_list)
#=> [2, 4]
```
All I did here was iterate over new_list and return only the even numbers.  This is similar to a filter function in JavaScript which we can call on an array.

```javascript
newArray = [1, 2, 3, 4, 5]
newArray = newArray.filter(num => num%2 === 0)
console.log(newArray)
//=> [2, 4]
```
However, the list comprehension in python is more powerful than just a filter, it can also perform the same action as a map function in JavaScript.

```python
new_list = [1, 2, 3, 4, 5]
new_list = [num*2 for num in new_list]
print(new_list
#=> [2, 4, 6, 8, 10]
```

This is just the surface of what comprehensions in Python can do but I am very much a fan of their syntax.

## Continuing to learn

For me, one of the best ways for me to learn is to simply use something. In Python, that means writing code and making applications. I have tried to make a few different simple CLI applications to further my understanding of Python. One similarity that made it easier for me to grasp is function definition syntax in both Python and JavaScript
```python
# Python

def foo():
    print('Hello World!')
foo()
```
```javascript
// JavaScript

function foo() {
    console.log('Hello World!')
}
foo()
```
Even though these two functions are a bit different, the way that they are invoked is the same which makes it easier for me to grasp how to actually print out 'Hello World!'.

## Next Steps

![](https://images.freeimages.com/images/large-previews/bab/sasha-1378238.jpg)

I am planning to be able to continue to practice Python using the Django web framework. I have started with Django but will need more time to be able to implement it the same way I could with a Rails application right now. I will also likely be writing about Python more as I continue to try to learn it so look out for a few more Python related posts here.

## References
* https://hackernoon.com/i-finally-understand-static-vs-dynamic-typing-and-you-will-too-ad0c2bd0acc7
* https://en.wikipedia.org/wiki/Strong_and_weak_typing
* https://en.wikipedia.org/wiki/Type_system