Learning about Data Types in Python
Written by Jacqueline Lim
What will I be covering today?
I will be covering mostly variables and data types, along with introducing Python 3 and a little bit of pseudocode for this post, and in my next post, I will cover operators and how they can be used.
Introduction to Python 3
What is Python 3? It is a programming language that has risen to be one of the most popular programming languages in the world.
How were Python 3 and its predecessors able to rise to the top?
It has to do with the fact that Python 3 is easier and less complicated to use and learn when compared to other programming languages like Java/JavaScript.
Some reasons that Python 3 and the other versions of Python, in general, are easier for beginners to understand are code-readability (easy to read and understand), as it does not have to compile anything as it is already auto-complied for us, and that it does not have a lot of complicated functions.
Pseudocode
What is pseudocode and how does it help in learning?
There is also pseudocode, which is English written in a coded format, for example: Counting from 1 to 10 pseudocode:
x is 1 (also can be seen as x = 1)
While x is 1 less than 11:
x equals to x + 1
x will increase until it reaches 10 (11 is the stopping point)
Display/Print out x
Variables in Python
First off, what exactly are variables?
Well, they are values that we give to a container to hold, like in the Pseudocode example, we have x = 1 (or x is 1), and in this case, x is the container, while 1 is the value that x is holding.
x is 1/ x = 1 (1 is the variable, while x is the container)
What are the data types that can be found in Python?
There are many data types in Python, and the first data types that come to mind are integers (numbers), strings(words/alphanumeric), float (numbers with the decimal point), lists (can contain multiple values that are in square brackets), and boolean (true/false).
I will go into detail on how all of the data types work together in Python.
Integers and Floats
First up is integers, which can consist of numbers.
- An example of an integer would be 2.
x = 2 (2 is an integer and a variable)
There is also another data type that is similar to integer, and that is float, it is like an integer but it has a value after the decimal point.
- For example, 1.0 is considered a float, not an integer.
y = 1.0 (1.0 is a float and a variable)
Strings
The next data type that I will be covering is that of String (or str), this data type is the text that can include both numbers and letters.
- For example, "abc123" is a string variable, the same as "123abc".
z = "abc123" y = "123abc" #z and y are both string variables because of the double quotation marks ("").
Lists
The next type of data type that I will be covering is that of List, this data type can contain multiple values and the values have to be separated by a comma.
- For example, [0,1,2,3] is a list
i = [0, 2, 3] #i is a list data type because of the square brackets ([]).
Booleans
The last type of variable that I will be covering in this post will be that of boolean. A boolean is a data type that can have 2 possible values, true or false.
This is an example of how boolean can be used:
x = true
if x == true:
print("x is true")
else
print("x is false")
#output will be true
Conclusion
Python 3 is a wonderful programming language to kickstart beginners into learning coding, though there are several other programming languages that can serve the same purpose like Java/JavaScript.
Well, no matter what programming language one starts with, the most important part is that, by the end of the day, we'll all have a fun time learning or refreshing our minds on coding.