0% found this document useful (0 votes)
2 views3 pages

Python Notes

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python Notes

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1

Backend Points:
HTTP:
Application layer protocol used for transmitting Hypertext Document like HTML over the
internet. Allowing browsers to request and receive information from servers. It follows a client-
server model, where clients (like web browsers) send requests for resources, and servers respond
with the requested data. Each request contains a method (e.g., GET, POST) and headers, while
responses include status codes indicating success or failure. HTTP is stateless, treating each
request independently, and HTTPS provides a secure version using encryption for sensitive data.
Python:
1. List (`list`):
Lists are ordered collections of items that can hold elements of different data types. Lists are
mutable, meaning you can change their contents after they are created. Lists are represented by
square brackets ` [] `.
```python
my_list = [1, 2, 3, 4]
```

Methods:
- `append(item)`: Add an item to the end of the list.
- `extend(iterable)`: Extend the list by appending elements from the iterable.
- `insert(index, item)`: Insert an item at a specified index.
- `remove(item)`: Remove the first occurrence of a value from the list.
- `pop([index])`: Remove and return an element at the specified index (default is the last item).
- `index(item)`: Return the index of the first occurrence of an item.
- `count(item)`: Return the number of occurrences of an item.
- `sort()`: Sort the list in ascending order.
- `reverse()`: Reverse the elements of the list.
- `len()`: Return the length of the list.
2. Tuple (`tuple`):
2

Tuples are similar to lists, but they are immutable, meaning their contents cannot be changed
after they are created. Tuples are often used for heterogeneous data, and they are represented by
parentheses ` () `.
```python
my_tuple = (1, 2, 3, 4)
```

Methods:
- Tuples are immutable, so they have fewer methods compared to lists. Common operations
include indexing and slicing.
3. Dictionary (`dict`):
Dictionaries are collections of key-value pairs. Each key is associated with a value, and
dictionaries provide fast lookup based on keys. Keys must be unique within a dictionary, but
values can be duplicated. Dictionaries are represented by curly braces ` {} `.
```python
my_dict = {'a': 1, 'b': 2, 'c': 3}
```

Methods:
- `keys()`: Return a view of all keys in the dictionary.
- `values()`: Return a view of all values in the dictionary.
- `items()`: Return a view of all key-value pairs in the dictionary.
- `get(key[, default])`: Return the value for a key, or a default value if the key is not found.
- `pop(key[, default])`: Remove and return the value for a key, or a default value if the key is not
found.
- `popitem()`: Remove and return a (key, value) pair from the dictionary.
- `update([other])`: Update the dictionary with key-value pairs from another dictionary or
iterable.
4. Set (`set`):
Sets are unordered collections of unique elements. Sets do not allow duplicate elements, and they
are useful for tasks like removing duplicates from a list or performing set operations such as
union, intersection, and difference. Sets are represented by curly braces ` {} `.
3

```python
my_set = {1, 2, 3, 4}
```

Methods:
- `add(item)`: Add an element to the set.
- `update(iterable)`: Update the set with elements from an iterable.
- `remove(item)`: Remove an element from the set; raises a KeyError if the element is not
present.
- `discard(item)`: Remove an element from the set if it is present.
- `pop()`: Remove and return an arbitrary element from the set.
- `clear()`: Remove all elements from the set.
- `union(other_set)`: Return a new set containing all elements from both sets.
- `intersection(other_set)`: Return a new set containing only elements that are present in both
sets.
- `difference(other_set)`: Return a new set containing elements that are present in the first set but
not in the second set.
- `symmetric_difference(other_set)`: Return a new set containing elements that are present in
exactly one of the sets.

You might also like