What are Data Types and Variables? Flashcards
What’s a data type?
- The data type of an item is defined by the type and the range of values that an item can have.
-The data type of an item defines the type (integers, float, or complex numbers) and range of values (min to maximum) that item can have.
- For example, if a variable is of the data type “integer,” it means that it can hold whole numbers (positive, negative, or zero) within a specific range defined for integers. Similarly, if a variable is of the data type “floating-point,” it can store decimal numbers within a certain range. Each data type has its own set of rules and limitations.
- Data Type provides constraints and rules that help maintain data integrity and prevent unexpected behavior in programs.
What’s a variable?
- a name to which a value / a data can be assigned.
- variables allow us to give meaningful names to data.
What are the 3 main data types
in Python?
Numbers
Strings
Booleans
3 Main type of numbers in Python:
1. Integers
- Integers: The integer data type is comprised of all the positive and negative whole numbers.
1 3000 -50 - 32560
3 Main type of numbers in Python:
2. Floating point number
Floating-point numbers, or floats, refer to positive and negative decimal numbers.
0.00034 4.87 -34.7400
In Python, 5 is considered to be an integer while 5.0 is a float.
3 Main type of numbers in Python:
3. Complex number
Numbers made up of a real and an imaginary part.
Just like theprint()statement is used to print values,complex()is used to create complex numbers.
It requires two values. The first one will be therealpart of the complex number, while the second value will be theimaginarypart.
Here’s the template for making a complex number:
complex(real,imaginary)