In Python, everything is a value (object). Values are classified into types (classes) of data. There are 3 standard types of data:
- Numeric types
- Sequence types(Strings, Lists, Tuples)
- Mapping types (Dictionaries)
Numeric types: The 2 most common types of number are the integer (whole number) and the float (has decimals), but there’s also long (super long integers, written like integers but followed by an L) and complex (includes real and imaginary numbers).
Strings are a collection of characters stringed together that can be used to store like, anything. They’re immutable sequences of Unicode code points. To enter a string, use “” or ”. Btw, adding strings together is called concatenation. You can refer to a certain part of a string by using the index operator to get one character, e.g. [1], or by slicing it to get groups of characters, e.g. [1:3].
Lists are used to store an indexed list of items. They are created using [] and separating items with ,,,. They are mutable. The certain item in the list can be accessed by using its index in square brackets.
- To check if an item is in a list, use the in operator, which returns True if the item is in the list, and False if it is not.
- Append method adds an item to the end of an existing list, e.g. nums.append(4).
- Len function to get the number of items in a list, e.g. print (len(nums)).
- The insert method allows you to insert a new item at any position in the list.; the first argument is the index of the element before which to insert.
- The index method finds the first occurrence of a list item and returns its index.
- max(list): Returns the list item with the maximum value.
- min(list): Returns the list item with minimum value.
- list.count(obj): Returns a count of how many times an item occurs in a list.
- list.remove(obj): Removes an object from a list.
- list.reverse(): Reverses objects in a list.
- There’s a ton more -look’em up!
Tuples: pretty much lists, except they’re immutable, and they use ().
Ranges represent an immutable sequence of numbers, commonly used in for loops.
Dictionaries are the relation between a key and a value given to that key, and the’re enclosed by {}. Basically, they relate values to objects. To retrieve the value of the key, use []. E.g.
>>>my_dct= {‘ramen’: 5, ‘pasta’: 3}
>>>my_dct [‘pasta’]
3
SOURCE: https://docs.python.org/3/library/stdtypes.html