Makindo Medical Notes"One small step for man, one large step for Makindo" |
|
---|---|
Download all this content in the Apps now Android App and Apple iPhone/Pad App | |
MEDICAL DISCLAIMER: The contents are under continuing development and improvements and despite all efforts may contain errors of omission or fact. This is not to be used for the assessment, diagnosis, or management of patients. It should not be regarded as medical advice by healthcare workers or laypeople. It is for educational purposes only. Please adhere to your local protocols. Use the BNF for drug information. If you are unwell please seek urgent healthcare advice. If you do not accept this then please do not use the website. Makindo Ltd. |
Python is a high-level, interpreted programming language known for its simplicity and readability. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python is widely used in web development, data science, automation, and many other fields.
# This is a single-line comment
""" This is a multi-line comment spanning multiple lines """
x = 10 # Integer y = 3.14 # Float name = "Alice" # String is_active = True # Boolean
if x > 5: print("x is greater than 5") elif x == 5: print("x is equal to 5") else: print("x is less than 5")
for i in range(5): print(i) # Prints 0 to 4 j = 0 while j < 5: print(j) j += 1 # Prints 0 to 4
def greet(name): return f"Hello, {name}!" print(greet("Alice")) # Output: Hello, Alice!
square = lambda x: x * x print(square(5)) # Output: 25
fruits = ["apple", "banana", "cherry"] print(fruits[0]) # Output: apple fruits.append("date") # Adds "date" to the list
coordinates = (10, 20) print(coordinates[1]) # Output: 20
person = {"name": "Alice", "age": 30} print(person["name"]) # Output: Alice person["age"] = 31 # Updates the value of "age"
unique_numbers = {1, 2, 3, 2, 1} print(unique_numbers) # Output: {1, 2, 3}
class Dog: def __init__(self, name, age): self.name = name self.age = age def bark(self): return f"{self.name} says woof!" my_dog = Dog("Buddy", 3) print(my_dog.bark()) # Output: Buddy says woof!
class Animal: def __init__(self, name): self.name = name def speak(self): pass class Dog(Animal): def speak(self): return f"{self.name} says woof!" my_dog = Dog("Buddy") print(my_dog.speak()) # Output: Buddy says woof!
import math print(math.sqrt(16)) # Output: 4.0
# Directory structure: # mypackage/ # __init__.py # module1.py # module2.py # In a Python file: from mypackage import module1 module1.some_function()
with open("example.txt", "r") as file: content = file.read() print(content)
with open("example.txt", "w") as file: file.write("Hello, world!")
try: result = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero!")
try: result = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero!") finally: print("This will always be printed")
import numpy as np arr = np.array([1, 2, 3, 4]) print(arr * 2) # Output: [2 4 6 8]
import pandas as pd data = {"name": ["Alice", "Bob"], "age": [30, 25]} df = pd.DataFrame(data) print(df)
import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) plt.xlabel("X-axis") plt.ylabel("Y-axis") plt.show()
import requests response = requests.get("https://api.github.com") print(response.status_code)
Python is a versatile programming language with simple syntax and powerful features. It supports various programming paradigms and is widely used in different fields. Understanding the basic syntax, control structures, functions, data structures, object-oriented programming, and libraries is essential for effective Python programming. With its extensive standard libraries and community support, Python is an excellent choice for beginners and experienced developers alike.