Python Modules and Data Types Explained

In Python, a module is a file that contains functions, variables, and classes that we can reuse in our programs. Modules help us organize code and make it more readable and efficient. 📌 Types of Python Modules: 1️⃣ Built-in Modules – Already available in Python Example: math – Mathematical operations random – Generate random numbers datetime – Work with date and time 2️⃣ User-defined Modules – Created by the user to reuse code 3️⃣ Third-party Modules – Installed using pip Example: numpy – Numerical calculations pandas – Data analysis # Python Program Demonstrating int, float, complex, and string Together # Function to perform integer operations def integer_operations(a, b): print("\n--- Integer Operations ---") print("Addition:", a + b) print("Subtraction:", a - b) print("Multiplication:", a * b) print("Division:", a / b) print("Floor Division:", a // b) print("Modulus:", a % b) print("Power:", a ** b) # Function to perform float operations def float_operations(x, y): print("\n--- Float Operations ---") print("Addition:", x + y) print("Subtraction:", x - y) print("Multiplication:", x * y) print("Division:", x / y) print("Rounded Value of First Number:", round(x, 2)) # Function to perform complex number operations def complex_operations(c1, c2): print("\n--- Complex Number Operations ---") print("Addition:", c1 + c2) print("Subtraction:", c1 - c2) print("Multiplication:", c1 * c2) print("Division:", c1 / c2) print("Magnitude of First Complex Number:", abs(c1)) # Function to perform string operations def string_operations(s1, s2): print("\n--- String Operations ---") print("Concatenation:", s1 + " " + s2) print("Uppercase:", s1.upper()) print("Lowercase:", s2.lower()) print("Length of First String:", len(s1)) print("Reversed First String:", s1[::-1]) print("Replace characters:", s1.replace("a", "@")) # Main Program def main(): print("===== Python Data Types Demonstration =====") # Integer input a = int(input("Enter first integer: ")) b = int(input("Enter second integer: ")) integer_operations(a, b) # Float input x = float(input("\nEnter first float number: ")) y = float(input("Enter second float number: ")) float_operations(x, y) # Complex input print("\nEnter complex numbers in form a+bj") c1 = complex(input("Enter first complex number: ")) c2 = complex(input("Enter second complex number: ")) complex_operations(c1, c2) # String input s1 = input("\nEnter first string: ") s2 = input("Enter second string: ") string_operations(s1, s2) print("\n===== Program Completed Successfully =====") # Run the program if __name__ == "__main__": main() #Python #Programming #Coding #LearnPython #Developer #TechSkills

  • graphical user interface, website

To view or add a comment, sign in

Explore content categories