Table of contents
No headings in the article.
Pyhton Data Types:
- Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data.
- Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
- Python has the following data types built-in by default: Numeric(Integer, complex, float), Sequential(string,lists, tuples), Boolean, Set, Dictionaries, etc
โ Python Data Structures:
Data structures are essential for efficient data organization in programming. Python simplifies learning these fundamentals compared to other languages.
List:
Lists are ordered and mutable, meaning you can change their elements after creation.
Elements in a list are enclosed in square brackets
[]
.Lists allow duplicate elements.
Example:
codemy_list = [1, 2, 3, 4, 5]
Tuple:
Tuples are ordered and immutable, meaning their elements cannot be changed after creation.
Elements in a tuple are enclosed in parentheses
()
.Tuples allow duplicate elements.
Example:
codemy_tuple = (1, 2, 3, 4, 5)
Set:
Sets are unordered and mutable, meaning you can change their elements after creation.
Elements in a set are enclosed in curly braces
{}
.Sets do not allow duplicate elements.
Example:
codemy_set = {1, 2, 3, 4, 5}
Now, if you want to see how to create and use these data structures in Python, you can try running the following code in a Python environment:
# List
my_list = [1, 2, 3, 4, 5]
print("List:", my_list)
# Tuple
my_tuple = (1, 2, 3, 4, 5)
print("Tuple:", my_tuple)
# Set
my_set = {1, 2, 3, 4, 5}
print("Set:", my_set)