
🐍Python
Personal Python notes authored by me, encompassing indexing, loops, functions, data types, and formatting essentials, continually updated
Python Notes
name = "Akash Kumar"
print(len(name)) # Outputs the length of the string
print(name[1:5]) # Outputs the substring from index 1 to 4 (excluding index 5)
print(name[1:-1]) # Outputs the substring from index 1 to the second last characterIndexing in Python:
Slicing in Python:
Arithmetic Operations in Python:
Augmented Assignment Operator in Python:
Working with Numbers in Python:
Math Functions in Python:
Array Creation:
Python Data Types and Ordering
Built-in Functions:
Primitive Types in Python:
Lexicographical Order:
ASCII Representation:
TERNARY OPERATOR
Logical Operators in Python
Range Function in Python
For-Else Loop in Python
Syntax:
Functions in Python
Defining a Function
Calling a Function
Return Statement
Keyword Arguments in Python:
For instance:
Optional Arguments in Python Functions
Double Asterisks (**kwargs) in Python
Scope of Variables in Functions
FizzBuzz Function
Lists
Unpacking Lists in Python
Unpacking list values to multiple variables in one line
Unpacking Lists and Extracting Last Number
Iterating Lists with Index Using enumerate
enumerateList Methods in Python
Adding Items to Lists
Removing Items from Lists
Retrieving Item Information
Sorting Lists
Example:
Sorting Lists with Key Parameter and Lambda Functions
Using a Function with key Parameter
key ParameterLambda Functions for Sorting
Use Cases of Lambda Functions
Map Function in Python
Filter Function in Python
List Comprehension in Python
Extracting names and ages from a list of tuples
Iterating through names and ages using a loop
Using list comprehension for filtering based on a condition
Additional list examples
Function For Zip
Stacks in programming operate on the principle of Last-In, First-Out (LIFO).
Similar to stacks, a queue follows the First-In, First-Out (FIFO) principle.
Tuples in Python
Operations on Tuples
Converting to Tuples
Iterating Over Strings to Create a Tuple
Swapping Variables in Python
But in Python, it can be efficiently achieved with one line of code:
Sets in Python
Set Operations
Dictionary Operations
To delete a key:
Dictionary Iteration
Comprehensions in Python
Generators
Unpacking Operator
Expections and Try
Format Specifiers in Python's f-strings
Floating-Point Formatting:
String Formatting:
Padding and Alignment:
Last updated