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
lenfunction -
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)
- Range: This is used to generate number sequences
- Python set: Refer Here
Refer Here for jupyter notebook
Modules and Functions
- One of the major principle in programming in Reusability which revolves around
DRYprinciple (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
- we are executing the module
- library:
- other module imports and calls the reusable functions (or classes or variable)
- executor:
- 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 directlymodule-namewhen module is imported
