Python Beginner's Guide - Data Types
Tags: python, beginners, programming, tutorial
Published: 2022-02-01 06:00:23

Before we dig deep into the details of python as a programming language, let's first understand its terminologies and some of the basic principles which will enable us to start building a basic idea which we will be working with moving forward.

In this particular article, we are going to focus on data types we have in python. Let's get started:

## Data Types
Data types are the different types of input data accepted by a programming language. They are mostly used in defining, declaring, and storing values/operations. 

Most commonly used include: (_int, float, str, bool, list, tuple, set, dict, & complex_)

When talking about data types in python, I personally would say they are housed under a parent category called standard data types, this parent has children representing different data types:

The parent categories include:

* Numbers - Used to store numeric values.
* Strings - Used to store a sequence of characters.
* Tuple - Used to store a collection of different data types, it is immutable meaning no change happens over time.
* List - Used to store collection of different data types and it is mutable.
* Set - Stores unique elements.
* Dictionary - used to store different data types in the form of key value pairs.

## Variables
Variables are are names you can create in python to store values.

```python
myAge = 22
print(myAge)
```
In the example above we have a variable named _myAge_ which is assigned an integer value of 10, when printing all we need to do is pass in the variable name in the print function.

When using variable in python, here are a few thing to keep in mind:
* They are case sensitive.
* You should not use keywords.
* Must start with a letter or an underscore.

Let's break the standard data types down, and get an understanding of what lies where.

### 1. Numbers
We have 4 types of numeric data types, that is:
* int - stores whole numbers
* float - store floating point number eg x=35.6
* long - stores higher range of integers eg y=708060L
* complex - although it is not commonly used, it is used to store complex numbers like x=b+5c

### 2. Strings
Strings can be defined as a sequence of characters usually enclosed in quotation marks either single or double. 
```python
#example of strings: "hello", "hey you", "lary mak"
```
In python 3, Strings are immutable, but it can still be modified with the help of commands like **replace()** or **join()**.

#### How to Create Strings
In python strings can be written in 3 ways, that is with either single, double or triple quotes.

```python
my_name = "lary mak" #double quotes
my_bio = 'a growing developer sharing what I learn with the community' #single quotes
more_bio = ''' I believe with help of a community you are able
to achieve a lot of opportunities. Keep practicing and learning''' #triple quotes
```
#### String Concatenation
This is combining more than one strings together using the **+** operator. like below:
```python
first_name = "lary"
last_name = "mak"
print("Hello" + ' ' + first_name + ' ' + last_name) # Hello lary mak
```
> you can not concatenate two different data types. example int with a string, It will result in an error.

#### String Replication
This allows one to repeat the same string several times. It is done using the __*__ operator. 
```python
print("Dev Community" * 10)
```
This will print Dev Community 10 times in a row.

### 3. Tuple
It is similar to a list, but in tuple, **()** are used. It is within the brackets where all the elements are stored. Tuples are immutable.

```python
temp  = (36, 33)
```

### 4. List
It is a compound data type, meaning it is made of different data types. Lists are stored in **[]**, square brackets. List is used to store an array of items. They are mutable.
 
```python
student_marks = [9.1, 8.8, 7.5]
```

### 5. Dictionary
They are ordered, mutable and stores unique keys as a set. In order for one to create a `dict`, **{}** are used
```python
student_marks = {"Jane":9.1, 8.8, 7.5, "Martha": 6.8, 7.5}
```
We have covered some of the most commonly used data types in python, in the the next part of this series we will get cover more on Functions $ Conditions.

__Incase you missed__
* [Python Beginners Guide - Introduction to Python](https://dev.to/larymak/python-beginners-guide-introduction-to-python-3icj)

See you in the next one!

<a href="https://www.buymeacoffee.com/lary" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>

Connect With me at [Twitter](https://twitter.com/larymak1) | [GitHub](https://github.com/larymak) | [YouTube](https://www.youtube.com/channel/UCrT1ARRZfLOuf6nc_97eXEg) | [LinkedIn](https://www.linkedin.com/in/hillary-nyakundi)  | 

Enjoy Coding ❤.