New Training: Python Variables and Data Types
In this 5-video skill, CBT Nuggets trainer Ben Finkel writes our first scripts from scratch and understand the critical role that variables play in a program’s execution. We’ll also discuss the primitive data types available in Python. Watch this new Python training.
Learn Programming and Development with one of these courses:
This training includes:
- 5 videos
- 53 minutes of training
You’ll learn these topics in this skill:
- Understanding Variables
- Understanding Python Data Types
- Casting Data Types
- Python Literals
- Putting it All Together
The Four Primitive Data Types In Python
Like most programming languages, Python has access to primitive data types. These primitive data types are the most basic types of information. They are the building blocks on which all other things in Python are built on. For example, you can't create arrays or collections in Python without these data types. So, let's take a look at these four primitive data types and what they are.
An integer is a basic whole number without a decimal point. It's considered the most accurate primitive data type in all programming languages.
Floats are numbers with a decimal point. Floats can contain fractions of a number as well. Floating-point values are not considered as accurate as integers. For example, if you are performing a comparison operator on a float value you will most likely need to compare that data between a range of decimal values.
Strings are alphanumeric data. They can contain both numbers and letters. Note that a string value of 3 is not the same as an integer value of 3, though. In these cases, you will need to convert the string to a number before you can make comparisons against that data.
A Boolean is a simple true or false value. Think of it as being either off or on. It doesn't represent numbers or characters in any way.