Introduction to Python
Tags: python, beginners
Published: 2022-10-10 04:41:10

## Basic Information about Python

Python is quickly becoming one of the most popular coding languages out today. This is because it is packed with functionality, and is a relatively beginner-friendly language syntactically. In this post, we will explore some of the basic concepts in python, how they relate to JavaScript, and a brief history of how Python came to be as popular as it is today.

## History of Python

According to [Python Institute](https://pythoninstitute.org/about-python#:~:text=Python%20was%20created%20by%20Guido,called%20Monty%20Python's%20Flying%20Circus.), Python was created by Guido van Rossum and originally released on February 20, 1991. Later, in 1999, Guido van Rossum defined his goals for Python as follows:
- an easy and intuitive language just as powerful as those of the major competitors

- open source, so anyone can contribute to its development

- code that is as understandable as plain English

- suitable for everyday tasks, allowing for short development times.


 Another fun fact about the programming language is that even though most think it is in reference to the snake, Python got its name from an old BBC comedy sketch series called _Monty Python's Flying Circus_. Python did not have as quick of a rise as something like JavaScript, but year after year the number of users of the language continues to increase. According to the [Stack Overflow Developer Survey](https://survey.stackoverflow.co/2022/#most-popular-technologies-language) taken in 2022, Python is the fourth most popular language. Python ranks lower than JavaScript, HTML/CSS, and SQL.

## Basic Syntax and Operations

One of the notable differences about Python, as it relates to JavaScript, is that there are no "var", "let", or "const" variable declarations. Instead, variables are just named and set to a value with no declarative keyword. As far as actual usage of these variables, they behave very similarly to JavaScript variables. Basic operations like addition, subtraction, division, multiplication, and the modulus operator exist and operate just as they do inside of JavaScript, allowing us to add numbers, concatenate strings, and pretty much any other operation contained within the Python library.

One notable difference between JavaScript and Python is the way comments are written. In Python, a single line comment is written using the hash character(#), and will extend the comment to the end of the current line. For multi-line comments, a triple quotation is used("'). 

## Basic Python Operation Examples

First we will go over simple concatenation as well as printing values in Python. As mentioned earlier, there are no declarative variable keywords, so all the programmer needs to do is name their variable and set it equal to a string or other value.


![Variable Declaration and String Concatenation in Python](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39mdk666mo6kfggbmydb.PNG)

In the above snippet we have created three variables, each containing a piece of a sentence to be concatenated. Once the strings are stored in the variables, its as easy as creating a fourth variable and setting it equal to the concatenation of the first three. This example will "print" the sentence "This is an example of creating and concatenating in Python!". Pretty simple, right?

## Looping In Python

Loops, like in many coding languages, are used to repeat a task several times without having to rewrite the code to do so. Structurally, and in operation, Python's loops are quite similar to that of JavaScript. Let's take a look at a couple examples of these loops.


![Loops in Python](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hu7bnkgw81s8elsz8f5.PNG)

In the two examples above, we looped through numbers 1-10, and in the second example, we multiplied a number by two each time and printed it as long as it was less than the value of 100. 


## Lists in Python

The next concept we are going to cover is lists in Python as well as interacting with them, which are quite similar to JavaScript. Lists can hold different types of data upon initialization, or can be initialized empty and added to at a later time. Just like a JavaScript array, Python's lists are zero-indexed and can be accessed using the index. Below shows a few, but far from all, of the useful methods a programmer can use to interact with values in a list.


![List Methods in Python](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dpmqpfxz9yuq3dffqz1.PNG)

## Dictionaries in Python

In Python, the dictionary is similar to an object in JavaScript, having a key as well as a value. Just like in JavaScript, dictionaries can be more complex than lists, but also have a bit more functionality. Similar to objects in JavaScript, you can't have duplicate key values. Trying to add a value to a key that is already assigned will just overwrite the existing value. Additionally, just like the lists in python, you are able to initialize an empty dictionary in Python and add values at a later time. One of the more recent changes in Python, according to W3 Schools, is that dictionaries in python are now ordered. This means that the items have a defined order and will not change. This means that you can technically get values or keys from a dictionary using index value, however, this is not advised as removing an element will shift the index values of each other element contained in the dictionary. This can make things cloudy and lead to bugs so it is usually best to use a different method to return data from a dictionary. 


![Examples of Python Dictionaries](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5cmpsjsx3dtt9wsosbvr.PNG)

## Conclusion

All in all, I've only taught myself a little bit of Python in my free time, so this post is barely scratching the surface of the capabilities of Python, but hopefully a little bit of introduction to the language has you curious enough to go and learn a few more things about Python. Included below in my sources are everything used to write this article as well as some generally helpful and interesting information about the language. Thanks for reading!






**Sources:**
[Python Docs](https://docs.python.org/3/)
[Stack Overflow Developer Survey 2022](https://survey.stackoverflow.co/2022/#most-popular-technologies-language)
[Python Institute](https://pythoninstitute.org/about-python#:~:text=Python%20was%20created%20by%20Guido,called%20Monty%20Python's%20Flying%20Circus.)
[W3 Schools](https://www.w3schools.com/python/default.asp)
[Python Essay with language comparison link](https://www.python.org/doc/essays/blurb/)