Cheat Sheet: Python Basics
| Package/Method | Description | Code Example |
|---|---|---|
| Comments | Comments are lines of text that are ignored by the Python interpreter when executing the code<./td> |
|
| Concatenation | Combines (concatenates) strings. | Syntax:
Example:
|
| Data Types | - Integer - Float - Boolean - String | Example:
|
| Indexing | Accesses character at a specific index. | Example:
|
| len() | Returns the length of a string. | Syntax:
Example:
|
| lower() | Converts string to lowercase. | Example:
|
| print() | Prints the message or variable inside `()`. | Example:
|
| Python Operators | - Addition (+): Adds two values together. - Subtraction (-): Subtracts one value from another. - Multiplication (*): Multiplies two values. - Division (/): Divides one value by another, returns a float. - Floor Division (//): Divides one value by another, returns the quotient as an integer. - Modulo (%): Returns the remainder after division. | Example:
|
| replace() | Replaces substrings. | Example:
|
| Slicing | Extracts a portion of the string. | Syntax:
Example:
|
| split() | Splits string into a list based on a delimiter. | Example:
|
| strip() | Removes leading/trailing whitespace. | Example:
|
| upper() | Converts string to uppercase. | Example:
|
| Variable Assignment | Assigns a value to a variable. | Syntax:
Example:
|
Comments
Post a Comment