Python 101
In Python, there are several built-in data types that you can use to store and manipulate data. These data types include:
- Integers: Integers are whole numbers that can be positive, negative, or zero. For example, 10, -5, and 0 are all integers. In Python, integers are represented using the
int
data type. - Floating-point numbers: Floating-point numbers are numbers that have a decimal point. For example, 3.14, -0.01, and 0.0 are all floating-point numbers. In Python, floating-point numbers are represented using the
float
data type. - Strings: Strings are sequences of characters, such as words or phrases. In Python, strings are represented using the
str
data type. Strings can be enclosed in single quotes (') or double quotes ("), but the quotes must match. - Booleans: Booleans are data types that can have only one of two values:
True
orFalse
. In Python, Booleans are represented using thebool
data type. - Lists: Lists are ordered collections of items. Lists can contain items of any data type, including other lists. In Python, lists are represented using square brackets [].
- Tuples: Tuples are similar to lists, but they are immutable, which means that they cannot be modified after they are created. Tuples are represented using parentheses ().
- Sets: Sets are unordered collections of unique items. In Python, sets are represented using curly braces {}.
- Dictionaries: Dictionaries are collections of key-value pairs. In Python, dictionaries are represented using curly braces {}.
Each of these data types has specific properties and methods that you can use to manipulate and access the data they contain. For example, you can use the len()
function to get the length of a string, list, tuple, or dictionary, or you can use the sort()
method to sort the items in a list.