Python Handwritten Notes
1. Built-in Functions
- print(): Displays output on screen.
Example: print("Hello") -> Hello
- input(): Takes input from user as string.
Example: name = input("Enter name: ")
- int(): Converts a string or float to integer.
Example: int("5") -> 5
- str(): Converts number to string.
Example: str(10) -> "10"
- type(): Returns data type.
Example: type(5) -> <class 'int'>
2. List Methods
- append(): Adds item at end of list.
Example: nums = [1, 2]; nums.append(3) -> [1, 2, 3]
- insert(index, item): Adds item at specific index.
Example: nums.insert(1, 5) -> [1, 5, 2, 3]
- pop(): Removes and returns last item.
Example: nums.pop() -> 3, list becomes [1, 5, 2]
- remove(item): Removes first occurrence of item.
Example: nums.remove(5) -> [1, 2]
Python Handwritten Notes
- sort(): Sorts list in ascending order.
Example: nums.sort() -> [1, 2]
- reverse(): Reverses the list.
Example: nums.reverse() -> [2, 1]
3. Type Conversion
- float(): Converts to float.
Example: float("3.5") -> 3.5
- bool(): Converts to boolean.
Example: bool(0) -> False, bool(1) -> True
- list(): Converts iterable to list.
Example: list("abc") -> ['a', 'b', 'c']
4. Useful Operators
- + : Addition / Concatenation
- - : Subtraction
- * : Multiplication / Repetition (for strings)
- / : Division
- // : Floor Division (removes decimal)
- % : Modulus (remainder)
- ** : Exponent (power)
Example: 2 ** 3 -> 8
5. Conditions and Loops
Python Handwritten Notes
- if, elif, else: Used for decision making.
Example:
if age > 18:
print("Adult")
elif age == 18:
print("Just adult")
else:
print("Child")
- for loop: Iterates over a sequence.
for i in range(3): print(i) -> 0 1 2
- while loop: Repeats while condition is true.
i = 0
while i < 3:
print(i)
i += 1