Data Types:
- int: Integers with no decimal part ( eg 2, -30, 14)
- float: Numbers with a decimal part, even if that part is zero ( eg 2.5,3.141,-3.0)
- str: Strings are how we store text data in Python. Strings are strings of characters between either double quotes (“”) or single quotes (‘’)
- booleans: Booleans are variables that only have two different values: True and False.
- list: Lists are ordered (elements have a particular order that will never change), mutable (they can be changed), heterogeneous (they can hold values of different data types) collections. We can tell Python we’re creating a list by wrapping the items in square brackets [].
- tuples: Tuples are immutable (once made, they can never be changed), heterogeneous (they can contain values of different types). To define a new tuple, use parentheses () instead of brackets. Tuples are used for information that won’t change.
- sets: A set is a collection of unordered, unique elements. To tell Python we’re writing a set, we use curly braces {}.
- dictionaries: Dictionaries are unordered, mutable key-value pairs. As with sets, a dictionary is defined using curly braces {}. However, each element of a dictionary consists of a key, followed by a colon, then by a value.
— To create an empty set, use the built-in set() function (e.g., a_set=set()). Because in Python, curly braces are used for both sets and dictionaries. Empty braces {} indicate an empty dictionary.
Name Rules:
Variable naming rules (mandatory)
- Names can only consist of letters, underscores, and numbers.
- Names can’t begin with numbers
- You can’t name a variable after a built-in Python keyword (eg if).
Variable naming rules (good manners)
- Names should always be descriptive (ie, don’t name variables x and df)
- No capital letters
- Variables should not begin with an underscore ( because OOP)
- Multi-word variables should be in snake_case. All lower case separated by underscores.
- Technically, you can name variables after built-in Python functions (like print), but it’s an extremely bad idea to do so. (Rule of thumb: If a variable name turns green, don’t use it)