Python Classroom notes 26/Apr/2025

Sequence Types

  • All the sequence types can hold multiple values in it
  • Sequence types supports indexes where we have positive and negative indexes

  • All sequence types support len function
  • Sequence types support slicing start-index:stop-index:step
    • start-index: default value is 0
    • stop-index: default value is length
    • step: it has default value of 1
  • Refer Here for data types
  • Sequence types:
    • list
    • tuple
    • range: it is used to create sequences
  • list:
    • can hold multiple types
    • is mutable
    • syntax: []
  • tuple:
    • can hold multiple types
    • are immutable
    • syntax: ()
  • We can convert between list and tuple
  • We can loop through lists, tuple using while
  • For loop in python Refer Here
for item in items:
    print(item)

Refer Here for jupyter notebook

Modules and Functions

  • One of the major principle in programming in Reusability which revolves around DRY principle (Dont Repeat yourself)
  • Module is a python file
  • Function is a reusable code which exists in a module
  • modules can be reused or functions, classes or variables in module can be reused
  • To document modules and functions lets use docstrings, Lets use Google’s style guide for this
  • Docstring for a module
  • Docstring for function and methods
  • Functions
  • To name a function we use snake casing
  • Module can be used in two ways
    • executor:
      • we are executing the module python <module-name>.py
    • library:
      • other module imports and calls the reusable functions (or classes or variable)
  • Module import options
  • option 1: import
import utils

if utils.is_even(10):
    print("even")
  • option 2: from import
from utils import is_even

if is_even(10):
    print("even")
  • Whenever you see anything in python with double underscores (dunder) around it, it has special purpose and is defined by python.
  • Lets discuss about a special dunder variable __name__ which will have two possible values
    • __main__ when the module is executed directly
    • module-name when module is imported
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%