25
loading...
This website collects cookies to deliver better user experience
Python Installation and development environment set up.
Comments and statements in Python.
Variables in Python.
Keywords, identifiers and literals.
Operators in Python.
Comparison operators and conditions
Data types in Python
Control flow.
Functions in Python.
Basics data structures, these lists, tuples, dictionary set.
Functions and recursion.
Anonymous or lambda function in Python.
Global, Local and Nonlocal.
Python Global Keyword.
Python Modules.
Python Package.
Classes in Python.
Closures and decorators
Inheritance and Encapsulation.
# how to create a list.
todo = ['sleep', 'clean', 'sleep']
# how to access or edit a list items.
todo[0] = 'vacuum'
# how to add an items.
todo.append('mow yard')
# how to remove an items
todo .remove('sleep')
# how to create a tuple
student = ("freshman", 15, 4.0)
# how to access an item
print(student[0])
# how to access items
print(student[0:2])
# Hoe to delet a tuple
del student
mycar = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
myset = {"apple", "banana", "cherry"}
print(myset)
If you have 16 lines of code which appears 4 times in a program, you don't have to repeat it 4 times. You just write a function and call it.
Re-userbility of code minimises redundancy.
Procedural decomposition makes things organised.
def my_function(x):
return list(dict.fromkeys(x))
mylist = myfunction(["a", "b", "c", "d"])
print(mylist)
my_function()
def sum(a,b):
print(a+b)
# Here the values 1,2 are arguments
sum(1,2)
def sum(a,b):
print(a+b)
# Here the values 1,2 are arguments
sum(1,2)
from fastapi import FastAPI
app = FastAPI()
#Here is the decorator
@app.get("/")
async def root():
return {"message": "Hello World"}
lambda arguments: expression
double = lambda x: x * 2
print(double(5))
x = "global"
def foo():
print("x inside:", x)
foo()
print("x outside:", x)
def foo():
y = "local"
foo()
print(y)
def outer():
x = "local"
def inner():
nonlocal x
x = "nonlocal"
print("inner:", x)
inner()
print("outer:", x)
outer()