Avatar Image
Gajendra Mahato

โœ… `floor()`

Returns the nearest whole number less than or equal to the given number. import math math.floor(3.5) # 3 math.floor(3.9) # 3 math.floor(-3.5) # -4 math.floor(-2.8) # -3 โœ… trunc() Cuts off the decimal part and moves the number towards zero. math.trunc(2.8) # 2 math.trunc(-2.8) # -2 ๐Ÿ” Number Conversion โžค Binary bin(2) # '0b10' int('10', 2) # 2 โžค Octal oct(64) # '0o100' int('100', 8) # 64 โžค Hexadecimal hex(64) # '0x40' int('40', 16) # 64 ๐Ÿ”ข Decimal Used for exact decimal values (like money). ...

January 13, 2026 ยท 1 min

โœ… String Basics in Python

chai = "Masala Chai" print(chai[0:6]) # Masala โ†’ gets characters from index 0 to 5 print(chai.lower()) # masala chai โ†’ converts all to small letters print(chai.upper()) # MASALA CHAI โ†’ converts all to capital letters print(chai.strip()) # Masala Chai โ†’ removes space from start and end only print(chai.replace("Masala", "Lemon")) # Lemon Chai โ†’ replaces word print(chai.find("Chai")) # 7 โ†’ shows starting index of word print(chai.count("Chai")) # 1 โ†’ counts how many times word appears โœ… split() โ€“ splits string into list chai_list = "Lemon, Ginger, Masala, Mint" print(chai_list.split()) # ['Lemon,', 'Ginger,', 'Masala,', 'Mint'] โ†’ split by space (default) print(chai_list.split(", ")) # ['Lemon', 'Ginger', 'Masala', 'Mint'] โ†’ split by comma + space โœ… String Slicing num = "0123456789" num[:] # '0123456789' โ†’ full string num[3:] # '3456789' โ†’ from index 3 to end num[:7] # '0123456' โ†’ from start to index 6 num[0:7:2] # '0246' โ†’ step 2 from index 0 to 6 num[0:7:3] # '036' โ†’ step 3 from index 0 to 6 โœ… String Formatting chai_type = "Masala" quantity = 2 statement = "I ordered {} cups of {} chai" print(statement.format(quantity, chai_type)) # Output: I ordered 2 cups of Masala chai

January 13, 2026 ยท 1 min

Object Types / Data Types

Number: 1234, 3.1415, 3+4j, 0b1111, Decimal(), Fraction() Examples of numbers, including integers, floats, complex, binary, Decimal, and Fraction. String: 'spam', "Bob's", b'a\x01c', u'sp\xc4m' Examples of strings, including regular, byte, and unicode strings. List: [1, [2, 'three'], 4.5], list(range(10)) List examples, including nested lists and lists generated from a range. Tuple: (1, 'spam', 4, 'U'), tuple('spam'), namedtuple Examples of tuples, including a basic tuple, a tuple from a string, and namedtuple. ...

January 13, 2026 ยท 2 min