Python Seminar – Detailed Notes
1. Datetime Module
The datetime module in Python is used to work with dates, times, and time intervals.
Classes in datetime:
• date – represents calendar dates (year, month, day)
• time – represents time (hour, minute, second)
• datetime – combination of date and time
• timedelta – represents duration/time difference
• timezone – contains information about time zones
Key methods in datetime class:
• now() – returns current local date and time
• today() – returns today's date
• utcnow() – returns current UTC time
• fromtimestamp() – converts UNIX timestamp to datetime
Uses:
• scheduling applications
• logging and timestamping
• time calculations
2. Namespaces and Scope
Namespace is a system that Python uses to store names (variables, functions, classes).
Types of namespaces:
• Local – inside a function
• Global – at script/module level
• Enclosing – in nested functions
• Built■in – provided by Python (print, len, etc.)
Scope determines which part of the program can access which names.
Scopes:
• Local scope – inside a function
• Global scope – outside all functions
• Enclosing scope – outer function
• Built■in scope – Python predefined
Namespace helps avoid variable name conflicts.
3. dir() Function
dir() returns all names defined in the current namespace or inside any module/class/object.
Examples:
• dir() – lists local names
• dir(math) – lists everything inside math module
• dir(str) – shows string methods
Useful for:
• learning modules
• debugging
• exploring classes
4. reload() Function
reload() allows reloading a module without restarting Python.
Usage:
import importlib
[Link](module_name)
Used when:
• module code changes during program execution
• rapid development and testing
5. Dot Operator
Dot operator (.) is used to access module members, class attributes, and object methods.
Examples:
• [Link](16) – sqrt from math module
• [Link]() – calling object method
• [Link]() – module → class → method
Dot operator prevents name conflicts by specifying exact location of functions or variables.