Python
Table of Contents
Python
Overview
Python is a high-level, interpreted programming language known for its readability and versatility. It's widely used in Web Development, data science, machine learning, and automation.
Core Concepts
Basic Syntax
- Indentation is significant in Python.
- Comments start with #.
Example Code
# Print a message print("Hello, world!") # Variables and data types x = 10 # Integer y = 3.14 # Float name = "Alice" # String is_active = True # Boolean # List my_list = [1, 2, 3, "apple"] # Dictionary my_dict = {"name": "Bob", "age": 30} # Conditional statement if x > 5: print("x is greater than 5") else: print("x is less than or equal to 5") # Loop for i in range(5): print(i) # Function def greet(name): print("Hello,", name) greet("Charlie")
Python's Type System
Python is dynamically typed, meaning variable types are determined at runtime. This offers flexibility but can lead to errors.To improve code reliability, Python introduced optional static type hints using the typing module
Additional Topics
- Exception Handling: Managing errors and exceptions.
- File I/O: Reading from and writing to files.
- regex Regular expressions: Pattern matching in text.