class Calculator:
@staticmethod
def add(a, b):
return a + b
@staticmethod
def sub(a, b):
return a - b
@staticmethod
def mul(a, b):
return a * b
@staticmethod
def div(a, b):
return a / b
x = 10
y = 3
print(Calculator.add(x,y))
print(Calculator.div(x,y))
Similar Posts
math Module
ByadminThe math module in Python is a built-in module that provides access to standard mathematical functions and constants. It’s designed for use with complex mathematical operations that aren’t natively available with Python’s basic arithmetic operators (+, -, *, /). Key Features of the math Module The math module covers a wide range of mathematical categories,…
List Comprehensions
ByadminList Comprehensions in Python (Basic) with Examples List comprehensions provide a concise way to create lists in Python. They are more readable and often faster than using loops. Basic Syntax: python [expression for item in iterable if condition] Example 1: Simple List Comprehension Create a list of squares from 0 to 9. Using Loop: python…
Anchors (Position Matchers)
ByadminAnchors (Position Matchers) in Python Regular Expressions – Detailed Explanation Basic Anchors 1. ^ – Start of String/Line Anchor Description: Matches the start of a string, or start of any line when re.MULTILINE flag is used Example 1: Match at start of string python import re text = “Python is great\nPython is powerful” result = re.findall(r’^Python’, text) print(result) #…
Curly Braces {} ,Pipe (|) Metacharacters
ByadminCurly Braces {} in Python Regex Curly braces {} are used to specify exact quantity of the preceding character or group. They define how many times something should appear. Basic Syntax: Example 1: Exact Number of Digits python import re text = “Zip codes: 12345, 9876, 123, 123456, 90210″ # Match exactly 5 digits pattern = r”\d{5}” # Exactly…
List operators,List Traversals
ByadminIn Python, lists are ordered, mutable collections that support various operations. Here are the key list operators along with four basic examples: List Operators in Python 4 Basic Examples 1. Concatenation (+) Combines two lists into one. python list1 = [1, 2, 3] list2 = [4, 5, 6] combined = list1 + list2 print(combined) # Output: [1, 2, 3,…
Employee Class using Instance & Class Variables
ByadminChallenge: Employee Class using Instance & Class Variables Objective: Create an Employee class that uses both instance variables and a class variable. 1. Class Properties (Variables) 2. Employee ID Rules 3. Class Methods (Functions) 4. Key Summary