Datatypes
|
Casting
Casting is converting a datatype to another |
Input & Output (I/O)
|
Packages |
Operators
for membership operators , in dictionaries it only checks the keys and not values |
Module
----------------- -----------------
----------------- -----------------
|
List's Basic Operations
A list is a data structure that holds : 1) multiple data at once 2) of different data types ( , , )3) can store duplicates > we can create lists using brackets [ ] or the list() constructor |
Other Lists Methods
|
List Comprehensions
|
Python Tuples
A tuple is a data structure that : - holds multiple data at once - of different types ( , , )- can store duplicates - is so we cannot modify its items (this makes it faster to iterate over compared to lists) , meaning no delete or assignement operationswe can create lists using brackets or just comma seperated value (meaning the are optional) like follows :
|
Dictionaries
A dictionary is a data structure and a collection that : - allows us to store data in key-value pairs. - dictionary keys must be immutable, such as tuples, strings, integers, etc meaning we cannot use mutable (changeable) objects such as lists as keys. - dictionary values must be mutable of course We create dictionaries by placing key:value pairs inside curly brackets { }, separated by commas |
Other Dictionary Methods
|
Sets
A Set is data structure that : - Stores different data types - Cannot have duplicates - has immutable elements unlike lists and dictionaries In Python, we create sets by placing all the elements inside curly braces { } , separated by comma or using the set() constructor.
|
Set Operations
|
Python Strings
Python strings are immutable meaning we cannot change them , but we can assign its variable to another string which can do the job :
|
Python Files
|
File Operations
|
Directory Management
A Directory is a collection of files and subdirectories. A directory inside a directory is known as a sub-directory . Python has the module that provides us with many useful methods to work with directories (and files as well). |
Conditionals
|
Loops
|
Functions & Arguments
If you do not know how many arguments that will be passed into your function, add a before the parameter name in the function definition which will make the param an arbitrary argument |
Variables Scopes
we can use the keyword when we are inside a function , and we want to read and write a global variable inside a function. |
Lambda Functions
Lambda functions are also called anonymous functions because they have no name |
Python OOP
|
Exception Handeling
Exceptions can terminate the program's execution , that's why it is important to handle them when an exception occurs, the rest of the code inside the try block is skipped. If none of the statements in the try block generates an exception, the except block is skipped. In Python, the finally block is always executed no matter whether there is an exception or not. |
Python Exceptions
An exception is an unexpected event (error) that occurs during program execution , for example :
The above code causes an exception as it is not possible to divide a number by 0. |