Variables and Assignment:
In many programming languages, variables are best thought of as containers or buckets into which you put data. So in C, for example, when you write
Basic Data Types:
A tuple is a one-dimensional, immutable ordered sequence of items which can be of mixed data types.
In many programming languages, variables are best thought of as containers or buckets into which you put data. So in C, for example, when you write
// C code
int x = 4;
you are essentially defining a "memory bucket" named x, and putting the value 4 into it. In Python, by contrast, variables are best thought of not as containers but as pointers. So in Python, when you writex = 4
you are essentially defining a pointer named x that points to some other bucket containing the value 4. Python Variables Are Pointers.Basic Data Types:
Built-In Data Structures:
We have seen Python's simple types:
int
, float
, complex
, bool
, str
, and so on. Python also has several built-in compound types, which act as containers for other types. These compound types are:Type Name | Example | Description |
---|---|---|
list | [1, 2, 3] | Ordered collection |
tuple | (1, 2, 3) | Immutable ordered collection |
dict | {'a':1, 'b':2, 'c':3} | Unordered (key,value) mapping |
set | {1, 2, 3} | Unordered collection of unique values |
Dictionaries are extremely flexible mappings of keys to values, and form the basis of much of Python's internal implementation. They can be created via a comma-separated list of
key:value
pairs within curly braces. You can view the keys and values in a dict, either separately or together, using the syntax shown here
A set is an unordered collection of unique elements.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.