| March 21, 2024, 3:26 p.m.
Integer (int): Represents whole numbers without any fractional part. Used for counting and indexing.
Floating-point (float): Represents real numbers with a decimal point or an exponent notation. Used for calculations involving decimal numbers.
String (str): Represents sequences of characters enclosed within single, double, or triple quotes. Used for text manipulation and representation.
Boolean (bool): Represents the two truth values True
and False
. Used for logical operations and conditional statements.
List: Represents ordered collections of items enclosed within square brackets []
. Used for storing and manipulating sequences of items.
Tuple: Represents ordered collections of items enclosed within parentheses ()
. Similar to lists but immutable (cannot be modified after creation).
Dictionary (dict): Represents unordered collections of key-value pairs enclosed within curly braces {}
. Used for mapping keys to values.
Set: Represents unordered collections of unique elements enclosed within curly braces {}
. Used for mathematical set operations like union, intersection, etc.
NoneType (None): Represents the absence of a value or a null value. Used as a default return value of functions that don't explicitly return anything.
So i gonna provide you with some code ex of the different data types:
Int:
age = 25
print(age) #Outputs 25.
Here the 'age' is a variable and holds 25 as it’s value. 25 is an integer.
Float:
temperature = 98.7
print(temperature) #outputs 98.7
Here the 'temperature' is a variable and holds 98.7 as it’s value. 98.7 is an float.
String(str):
name = "John Doe"
print(name) #outputs John Doe
Here the 'name' is a variable and holds John Doe as it’s value. John Doe is an string.
Boolean(bool):
is_raining = True
print(is_raining) #outputs True
Here the 'is_raining' is a variable and holds True as it’s value. is_raining is an boolean and can only handle True/False.
Too check types of data type you use type() function. Too know data types is a good foundation to start out with.