0% found this document useful (0 votes)
3 views3 pages

Python Seminar: Datetime, Namespaces, Functions

The document provides detailed notes on key Python concepts including the datetime module for handling dates and times, namespaces and scope for managing variable access, the dir() function for listing defined names, the reload() function for reloading modules, and the dot operator for accessing module members and methods. It outlines the classes and methods within the datetime module, types of namespaces, and their scopes, as well as practical uses for dir() and reload(). Overall, it serves as a comprehensive guide for understanding these fundamental Python features.

Uploaded by

babysmitha14
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Python Seminar: Datetime, Namespaces, Functions

The document provides detailed notes on key Python concepts including the datetime module for handling dates and times, namespaces and scope for managing variable access, the dir() function for listing defined names, the reload() function for reloading modules, and the dot operator for accessing module members and methods. It outlines the classes and methods within the datetime module, types of namespaces, and their scopes, as well as practical uses for dir() and reload(). Overall, it serves as a comprehensive guide for understanding these fundamental Python features.

Uploaded by

babysmitha14
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like