Use the `+` operator: `s3 = s1 + s2`
Use `+=` for appending: `s1 += s2`
Use `join()` for multiple strings: `''.join()`
Use f-strings: `f"{s1}{s2}"`
Use `format()`: `"{}{}".format(s1,...
Use `import script_name`
Use `from script_name import function_name`
Call a function with `function_name()`
Run a script from another script with `subprocess.run()`
Execute a script file with `exec(open("script_name.py").read())`
Use `runpy.run_path("script_name.py")`
Call...
Use `open("filename.txt", "r")`
Read the entire file with `file.read()`
Read one line with `file.readline()`
Read all lines with `file.readlines()`
Iterate through the file with `for line in file:`
Use...
Use square brackets: `my_list = `
Use `list()`: `my_list = list((1, 2, 3))`
Create an empty list: `my_list = `
Create an empty list with `list()`: `my_list...
Use curly braces with key-value pairs: `my_dict = {"name": "Alice", "age": 25}`
Use the `dict()` constructor: `my_dict = dict(name="Alice", age=25)`
Create an empty dictionary with curly...
Check whether Python is installed: `python --version` or `python3 --version`
Check whether pip is installed: `pip --version` or `pip3 --version`
Install Python from the official website...
Open a terminal or command prompt
Navigate to the project directory containing `requirements.txt`
Create and activate a virtual environment if needed
Run `pip install -r requirements.txt`
Verify the...
Open a terminal or command prompt
Check that Python is installed
Check that pip is installed
Run `pip install module_name`
Use `pip3 install module_name` if needed
Use `python -m...
Use `**` for exponentiation: `2 ** 3`
Use `pow(base, exponent)`: `pow(2, 3)`
Use `math.pow(base, exponent)` for floats: `math.pow(2, 3)`
Import `math` before using `math.pow`: `import math`
Use `**=`...
Use curly braces with key-value pairs: `{"name": "Alice", "age": 25}`
Use the `dict()` constructor: `dict(name="Alice", age=25)`
Create an empty dictionary: `{}`
Create an empty dictionary with `dict()`:...
Check whether Python is installed: `python --version` or `python3 --version`
Check whether pip is installed: `pip --version` or `pip3 --version`
If pip is already available, use...
Type `deactivate`
Press Enter
If you are using Conda, type `conda deactivate`
If you are inside a nested shell, exit that shell first
Close the terminal window if...
Install Python from python.org or your system package manager
Open a terminal or command prompt
Type `python` or `python3` and press Enter to start the interactive...
Open Safari or another browser
Go to https://www.python.org/downloads/
Download the latest Python installer for macOS
Open the downloaded .pkg file
Follow the installation prompts
Enter your Mac password if...
Install Python from python.org or your package manager
Open a terminal or command prompt
Verify installation with `python --version` or `python3 --version`
Run a Python file with...
Create a virtual environment: `python -m venv .venv`
Activate on Windows Command Prompt: `.venvScriptsactivate`
Activate on Windows PowerShell: `.venvScriptsActivate.ps1`
Activate on macOS/Linux: `source .venv/bin/activate`
Deactivate the virtual environment:...
Install Python from python.org
Choose a code editor or IDE
Open a new Python file with a .py extension
Write a simple statement like print("Hello, world!")
Save the...
Run `python --version`
Run `python -V`
Run `python3 --version`
Run `python3 -V`
In Python, run `import sys; print(sys.version)`
In Python, run `import platform; print(platform.python_version())`
In a Jupyter notebook, run `!python...
Install Python
Open Terminal or Command Prompt
Navigate to the folder containing the .py file
Run `python filename.py`
If needed, run `python3 filename.py`
On Windows, try `py filename.py`
If using...
Open a terminal or command prompt
Check that Python is installed
Check that pip is installed
Install a library with `pip install library_name`
Install a specific version with...
`import random`
`random.randint(a, b)` to get an integer between `a` and `b` inclusive
`random.randrange(start, stop, step)` to get a random integer from a range
`random.random()` to get...
Use `*args` to unpack a list or tuple into function arguments
Define the function to accept variable positional arguments with `*args`
Pass the array directly if...
Install Python
Save your code in a `.py` file
Open a terminal or command prompt
Navigate to the script’s folder
Run `python script.py`
Or run `python3 script.py`
On Windows, you...
Use `str.split()` to split by whitespace: `"a b c".split()`
Use `str.split(separator)` to split by a specific delimiter: `"a,b,c".split(",")`
Use `str.split(separator, maxsplit)` to limit the number of...
Open a terminal or command prompt
Check that Python is installed with `python --version` or `python3 --version`
Check that pip is installed with `pip --version` or...
Install Python from https://www.python.org/downloads/
Open a terminal or command prompt
Run `python -m pip install pygame`
Verify the installation with `python -c "import pygame; print(pygame.__version__)"`
If needed, use...
Open a terminal or command prompt
Check that Python is installed with `python --version` or `python3 --version`
Check that pip is installed with `pip --version` or...
Download Miniconda or Anaconda for your operating system from the official website
Run the installer
Follow the installation prompts
Accept the license agreement
Choose the installation location
Select whether...
Use curly braces with key-value pairs: `my_dict = {"name": "Alice", "age": 25}`
Use the `dict()` constructor with keyword arguments: `my_dict = dict(name="Alice", age=25)`
Use the `dict()`...
Download and install the latest Python from https://www.python.org/downloads/
During installation, check Add Python to PATH
Open Command Prompt
Run `python --version`
Run `python -m ensurepip --upgrade`
Run `python -m...
Open a terminal or command prompt
Upgrade pip: `python -m pip install --upgrade pip`
Install the package: `pip install package-name`
If needed, use Python 3 explicitly: `python3...
Install Python from python.org or your system package manager
Save the file with a .py extension
Open a terminal or command prompt
Navigate to the folder containing...
Install Python from python.org or your package manager
Choose a code editor or IDE
Learn basic syntax: variables, data types, operators
Write simple statements and print output
Use...