Datatypes

= = Datatypes ﻿When pro gramming, there is a specific way of typing in your coding. There are things called datatypes. Datatypes are a way to categorize the different forms of coding. In the end, they all work together to create a working program. There is a specific way the datatypes have to be written in order for the program to work correctly. There are a lot of different kinds of datatypes, but I am going to show you 5 different datatypes that work with the programming language, //Python.//

The first datatype is a called a //string.// A string is used to input text. Here is an example: "This is a string." When you type a string, you have to put quotations marks around it. That shows the computer that you want it to appear on the screen as:

 This is a string.  It has no special purpose. It is simply for writing text.

The next datatypes are called //numbers//. They are the only datatypes that can do math. You could not do math by making a string that says, "One plus Two." Numbers, or integers, are what you would use if you wanted to do math.

 Here are some examples:  4 AA  123  AA 987678 AA 91 + 4 For the first 3 numbers, the computer would just type 4 123 987678. But for the last one, the computer would figure out that 91 + 4 equals 95 and it would just show the number 95.

<span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Another datatype is called a //list.// Lists are collections of datatypes. They can hold strings, numbers, and dictionaries (dictionary is the next datatype explained.) A list is just used to hold information.

<span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Here is an example: <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">If you wanted to group together "Cat", "dog", and "BIRD", you would use a list. But first, you have to name the list. I am going to name my list Animals. <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Animals = ["Cat", "dog", "BIRD"] <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">The equals sign tells the computer that everytime you input Animals, it will give you this: <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">"Cat", "dog", "BIRD" <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Y <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 14px; line-height: 21px;">ou can use lists to group numbers also.

<span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Another type of datatype is called a //dictionary//. When using a dictionary, you are basically making what a real dictionary does. But with this dictionary, it doesn't just have to be for definitions. <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 14px; line-height: 21px;">Here's an example: <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">I want to tell everyone that an apple is red and that a chair is brown. First, I have to come up with a name for my dictionary. My dictionary's name is going to be "Color". <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">When you want to say, for example, that apples are red, you would type: <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">"apple": "red" <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">(remember to put " " around the strings.) <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Now do the same with the chair are brown. <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">"chair": "brown" <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Ok this works. But now all we have are 4 strings. To make it into a dictionary, you have to put { } around the whole thing. When you have more than one thing in the dictionary, separate them with a comma. <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">{ "apple": "red", "chair": "brown"} <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">You now have a dictionary. But to find it again, you would have to retype it. So, instead of having to retype it, you name it. Everytime you type the name, in this case "Color", it will show you the whole dictionary. <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Color = { "apple": "red", "chair": "brown"} <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Now, when you type Color, it will show you the dictionary. Now lets say you want to just know what the apple means. You have to type: <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Color["apple"] <span style="color: #008000; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">That would show you "red". Just make sure that when you look for a specific part in the dictionary, that you put [ ] around the word and not { }. That is how you use a dictionary.

<span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">The last kind of datatype that I am going to talk about is called a //tuple//. Tuples are almost exactly the same thing as a list. But, in a list you can change the information. In a tuple you cannot. <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Also, when making a tuple, you have to put around the information not [ ] like in a list. <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">Here's an example of how to write a tuple: <span style="color: #000080; font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 110%;">("dog", "cat", 1, "BIRD!!")

<span style="font-family: 'Trebuchet MS',Helvetica,sans-serif; font-size: 14px; line-height: 21px;">Back To Home