top of page
Search

Step 2 - Data Types

  • Writer: Coding GP Team Project
    Coding GP Team Project
  • Oct 14, 2020
  • 2 min read

Don't get intimidated by the title, it's really simple!



First of all, there is something called a variable, it's like a box that you label and put stuff into. You assign a variable, by using the "=" sign In programming languages, there are multiple types of data to put in a variable. Like the box aka variable "Toys" which has all the toys within it.


There are four rules to remember for variables:

  • A variable name must start with a letter or the underscore character.

  • A variable name cannot start with a number.

  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )

  • Variable names are case-sensitive (age, Age and AGE are three different variables)


There are various data types in coding; however, we will focus on the main four: String, Boolean, Integer and Float. So let's explain each of them!


String: A sequence of characters, which can include alphanumeric-special character combinations. What does that mean? A word is a string, a sentence is a string. Anything within double quotes ( " " ) is a string in programming. Here are a few examples:


word = "word"
sentence = "This is a sentence"

And voila, you have a string! The next one is Boolean.


Boolean: Now this may sound complicated, but its really simple. It's either True, or its False. There are no other options! Let's take an example, I am a boy; hence,


boy = True
girl = False

Remember, Boolean has to have the first letter capital, otherwise, python will not accept it.


boy = True [Correct]												
boy = true [Incorrect]														

Integers: They are basically your numbers, without decimal places. Any whole number is an integer! For example:


age = 15
year = 2020

And finally,


Float: They are integers with decimals! These are extremely useful in calculating something slightly more complex. For example:


height = 2.4
width = 1.8

Let's run the example below to see our work in action

Click here to move on to the next step!


 
 
 

Comments


©2020 by Code2Learn

bottom of page