#compsci #python 

Python doesn't have a system that solidly defines variable types first-hand, like C++ does, but instead has the syntax for the types' **literals** - expressions that generate these objects.

Python is *dynamically typed* (keeps track of types for you automatically), yet *strongly typed* (you can perform on an object only operations that are vaild for its type) ^aca865

| Object type | Example literals/creation |
| --- | --- | 
| [[Python Numbers]] | 1234, 3.1415, 3+4j |
| Strings | 'spam', "guido's", b'a\x01c |
| [[Python Lists]] | [1, [2, 'three'], 4] |
| [[Python Dictionaries]] | {'food':'spam', 'taste':'yum'}|
| [[Python Tuples]] | (1, 'spam', 4, 'U') |
| [[Python file object]] | myfile=open('eggs','r') |
| Sets | set('abc'), {'a','b','c'} |
| Other core types | Booleans, types, None |
| Program unit types | Functions, modules, classes | 
| Implementation-related types | Compiled code, stack tracebacks| 
*Most data types*

In Python, ***sequences*** are a positionally ordered collections of things. A case in point is either a string, or a list.

In Python, **mappings** are collections of other objects that store them by key instead of by relative position.

## Immutability of variables
Strings and some other data types are **immutable** - cannot be changed in-place after they are created.

Every object in Python is classified as either immutable or not. In terms of the core types, *numbers, strings, tuples* are immutable, while *lists and dictionaries* are not.

So in order to do operations on these kind of objects, new objects are instead created.

## Nesting
You can assign a variable of type A inside a variable inside of type B, as in: a list inside a dictionary, etc.
One immediate application is to represent [[Matrix|matrixes]]:
```python
M=[[1],[2],[3]]
print(M[2][0]) # 3
```

## Data management
Python has a feature known as *garbage collection* that cleans up unused memory as a program runs and frees the user from having to manage such details themselves. In Python, the space is reclaimed immediately, as soon as the last reference to an object is removed. ^9420a4

## Data type identification
In order to to identify a variable's data type, use the built-in type function:

```python
L='asdf'
type(L) # string
```

## Classes
[[Classes in Python ]] have their own specific attributes (called **state information**) and their functions (called **methods**).