Introduction to Python
What is Python?
Python is a high-level, interpreted, and general-purpose programming language. It emphasizes readability
and simplicity. Created by Guido van Rossum in the late 1980s.
History of Python
1980s: Guido van Rossum started developing Python as a hobby.
1991: First official release of Python 0.9.0.
2000: Python 2.0 introduced with list comprehensions & garbage collection.
2008: Python 3.0 released - not backward compatible.
Now maintained by the Python Software Foundation (PSF).
Why Use Python?
Easy to learn and write.
Huge community and libraries.
Versatile - used in web development, data science, AI/ML, automation, and more.
Cross-platform and open source.
Python Functions
Functions are blocks of reusable code.
Defined using the def keyword:
def greet(name):
return "Hello, " + name
Functions improve code organization and reduce repetition.
Built-in Functions
Python comes with many built-in functions like:
- print()
Introduction to Python
- len()
- range()
- type()
- input()
User-Defined Functions
You can create your own functions:
def add(a, b):
return a + b
Functions can take arguments and return values.
Python Modules
A module is a file with Python code (functions, classes, variables).
Helps organize code into logical parts.
Use the import keyword to bring in modules:
import math
print(math.sqrt(16))
Common Python Modules
- math - mathematical functions
- random - generate random numbers
- datetime - work with dates and times
- os - interact with the operating system
- sys - access system-specific parameters
Conclusion
Python is beginner-friendly and powerful.
Introduction to Python
Understanding functions and modules helps you build better programs.
Keep practicing to become proficient in Python!