Intro to Python
๐ Python Docs
๐ The Python Standard Library
๐ Python Cheatsheet
๐ Python Tutorial - W3Schools
๐ VsCode Linux setup
Example of Python script
#!/bin/python3- first lineUse
#for comments


Variables & Methods
โก๏ธ A variable is a dynamic container for storing data values.
โก๏ธ A method (or function) is a block of code which runs when called and performs specific operations. It can have return values, perform actions, accept parameters, etc.

โก๏ธ A function is a reusable block of code that performs a specific task.
defined with the
defkeyworddef function_name():
accepts parameters
โ Indentation is very important in Python, since it's used to indicate a block of code.

โก๏ธ Boolean expressions are expressions that evaluate to either True or False, used in conditional statements and logical operations.
โก๏ธ Relational operators are used to compare values and create boolean expressions.

โก๏ธ Conditional statements allow the execution of different actions based on certain conditions. Logical math conditions can be used in if statements and loops.

โก๏ธ Lists are used to store multiple items in a single variable.
list = ["item1", "item2", "item3"]items are ordered, changeable and indexed (first item index starts at
[0])

โก๏ธ Tuples are used to store multiple items in a single variable, similar to a list but immutable (cannot be modified once created).
tuple = ("item1", "item2", "item3")items are ordered, indexed and unchangeable

โก๏ธ Looping allows to repeat a block of code multiple times, iterating over a sequence and performing repetitive tasks.
forloop: iterate over a sequence and execute a set of statements for each item in a list, tuple, string, set, dictionarywhileloop: execute a set of statements as long as a condition is true


โก๏ธ Dictionaries are used to store, retrieve and manipulate data based on key:value pair values.
dictionary = {"item1":value, "item2":value, "item3":value}

โก๏ธ Modules are like code libraries, containing a set of functions to include in the application.
reside in external Python files/libraries
import <module>

โก๏ธ Sockets are used to send messages across a network, enabling programs to establish connections, send and receive data over various network protocols.
Primary socket module methods and functions are:
socket().bind().listen().accept().connect().connect_ex().send().recv().close()

Listen to the
5555port withncand launch thes2.pyPython script.the socket will connect to the listening port

e.g. Port scanner
Port scanning of an IP address
This port scanner is a proof-of-concept not optimized script, that checks for open ports on a specified target IP within a given range.
(ChatGPT) Enhanced script
Try to scan an internal LAN IP

โก๏ธ input() function is used to take input from the user via the console and return it as a string (by default). Proper validation and error handling is necessary for specific data types and invalid inputs.

โก๏ธ To read from a file, open it in read mode using open("filename", "r"). Then, use read(), readline(), or readlines() to access its contents.
โก๏ธ To write to a file, open it in write mode using open("filename", "w"). Then, use the write() method to add content to the file.
โก๏ธ To append content to an existing file, open it in append mode using open("filename", "a"). Then, use the write() method to add content.


โก๏ธ A class is a blueprint for creating objects, defining their attributes and methods. It serves as a template for creating instances with similar characteristics and behaviors.
โก๏ธ An object is an instance of a class, created using the class as a blueprint. Each object has its own attributes and can use the class's methods. You create objects by calling the class like a function.

Last updated
Was this helpful?