
Day 22 Python Learning
Just Simple class practice
not feeling well so not much to

Just Simple class practice
not feeling well so not much to
how to write calculator function
for real word use
and daily practice of :
if else,
for loop
while loop
def with return and *args ,**kwargs
not much try to make python alarm clock
which can accept user input
date : yyyy-mm-dd
time : hh:mm , AM/PM
and sound input
beep/ music
but any type of sound (music) you must have file
and truth to be told I do forget and get confused when writing like
how to I told python to check if its AM/PM
or try to raise error
I have to write more code properly understand
that's all for today
read and write file in python :
- read file (1st option not recommended need to close every time)
f = open('filename.txt')
data = f.read()
print(data)
f.close()
option 2 - automatically close when use
- with statement
it much better and clean
with open('python_4_4_file/my_17.1.txt') as f: print(f.read())
- write
warning ⚠️ which can overwrite if there is something inside file
f = open('python_4_4_file/my_17.1.1.txt','w') f.write(newline)
f.close()
-append can we use if you want to add in the file something in the end it's have same codeline as write just one small change in place of "w" change need to write "a"
f = open('python_4_4_file/my_17.1.1.txt','a')
practicing class & dunder method
if follow my previous day note then most of my brother & sister already know what is the class
class work like local apartment which have different room called function use __init__() to connect outside world
and like __init__ the Construction type there is more
- dunder method which used for to tell Python what to do
like __add__ Arithmetic type for +
same __sub__, __mul__, __truediv__, __pow__, etc. + r versions (__radd__) and more
first code
second one which is under comment
identical but still giving first one name 'Complex' is not defined. Did you mean: 'complex'?
yeah I know because of buildin function of python
but then I run second quote which is under comment
it's give perfectly fine answer
what going on
bahut code have Complex in capital letter C and
type is not in both condition
decorators & operation overload
- decorators
@classmetho use when we want to directly show / use class attribute not instance attribute
@properties use for read only and hide complexity
@setter use for show thing need to or user want to show not all detail info
[if you think ,I am not explain clearly or mis any part or wrong and also if you can describe more easily feel free to comment all opinion ideas is welcome. ]
class inheritage
- parents child or say mulit-inheritance use with super () when one class inheritance from one or more class
- multi-level inheritance where 2nd class in Heritage from 1st class ,3th inherited from 2nd & go on like family chain
solve some list comprehensive easy problem
late update thanks to Black out
yesterday learning was
- inheritance (parent - child method)
when the new class in Heritage from existing class like the same function why writer when it's exist just take it
- multi inherities
when you take inheritage from more than one class
today's learning not finish and look like need to more practice inheritage with project
it's easy but sometime get confusing
I was thinking about inherities to but
after opening hacker rank I was busy doing some solution
but it's not a way I learn
- list comprehensive
-and just now the class practice little Messy but did it
try to make password strength checker with only
- while
- for with any
- if & else
and OOP class exercise
finally time of class not school class
class in python:
- class is blueprint map in simple world which help you to know and create,control,manage what,where,why you want
- self in class
it used for read and change(overwrite)
-__init__
use to connect line with self can take many argument in place of default class
""" it may same confusing but it clear and easy """
just when writing in the beginning you may face error
#python #coding #ai
""" both function give 8 but ending and logic is defferent tell me what difference is ???"""
​
I don't know 😔 but what about you
​
#python #challenge #codingsect
function
- default argument
as name there is default option of argument which automatically apply
​
- *argument
use when we don't know number of argument
​
- **kwargs
when you want change any data ,number to dict aka dictionary use **
​
- recursion
it's repeat itself till we get result
factorial n = n*factorial (n-1)
#python #coding #ai
function of python
- def()
- argument statement in def(a,b)
- return function in def()
​
some logic before/ after use of print
- how it effect the final result
​
daily practice of terminal use
#python #coding #ai
Finally back to the town 😭
Focus on
-dictionary aka dict :
In dict every set have key and its value
We can call value by using key but not opposite
- set:
Unordered & only accept unique value not copy
​
And did some revision
Now give me idea for project building or for product ?
​
Before moving tomorrow in def function and class
#python #coding #ai
Tuple and more practice of if/else with combine for loop
​
​
​
\- trup is in ordered, but unchangeable
​
only check integer or slice,
​
tell me if I miss something
​
​
​
\- TypeError: tuple indices must be integers or slices, not tuple
​
​
​
\-if else,for loop and list practice
​
create store simple system product & price display
​
With additional trick to combine to list
​
Using zip(list1,list2)
#python #coding #ai
Tuple and more practice of if/else with combine for loop
​
- trup is in ordered, but unchangeable
only check integer or slice,
tell me if I miss something
​
- TypeError: tuple indices must be integers or slices, not tuple
​
-if else,for loop and list practice
create store simple system product & price display
With additional trick to combine to list
Using zip(list1,list2) #python #coding #ai
today start with simple practice using for and while loop
- while True
In which I make mistake put variable input () outside of while True which cause infinite loop 🥶 So never do at for in beginning of learning
- use for loop with " ".join() to create continuous triangle with number
- at last taste of terminal where I cause some errors because of lack of use of terminal,So need more time to use
​
Join me in python journey..
Let meet tomorrow, for now I am going to get taste of git🤤
#python #coding #ai
- list:
In we can use .append(item) to add any item in the end of the list,
Use .remove(item) to remove
Use len() to check length there is more
Note: list remain in order and changeable
​
- and for loop in list
Note better to practice more for loop so our mind can become comfortable with iteration
#python #coding #ai