Skip to content

Commit 68dd376

Browse files
committed
Added all docs for Module 8
1 parent 4215c68 commit 68dd376

20 files changed

+124
-0
lines changed

Diff for: Args.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Args and Kwargs
2+
```python
3+
The purpose of *args is that, *args are used to help the developer passing a variable number
4+
of arguments to a function.
5+
The symbol * makes args iterable which means that you can run a for loop and process
6+
every argument inside the args list.
7+
```
8+
### Example
9+
![Code1](/images/A1.png)
10+
```
11+
Now what if you want to pass a list and print every number in the list
12+
```
13+
![Code2](/images/A2.png)
14+
```python
15+
The list is getting printed in one line as the whole list is taken as 1 parameter.
16+
Suppose if you want to print each element of the list then while passing parameters in call add * before list name.
17+
```
18+
![Code3](/images/A3.png)
19+
```
20+
**kwargs help the developer to give arbitrary keyworded arguments to a
21+
function and access them later in a dictionary.
22+
We will see an example where we are passing 2 parameters to a
23+
function with 2 parameters and to a function with kargs parameter.
24+
```
25+
![Code4](/images/A4.png)
26+
```
27+
We can see that in the former case it is printing 1 1 so we cannot identify which is x and which is y, But in the latter case it is easily recognizable.
28+
29+
What if we only want to print the value of x then:
30+
```
31+
![Code5](/images/A5.png)
32+
```
33+
Now if we want to use *args and **kwargs together:
34+
First we should see to it that *args should always be before
35+
**kwargs or else it will throw an error message.
36+
```
37+
![Code6](/images/A6.png)
38+
![Code7](/images/A7.png)

Diff for: Format_Function.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Format Function
2+
```python
3+
The .format() method of the str type is an extremely convenient way to format text exactly the way you want it.
4+
Here is the general form:
5+
template.format(p0, p1, ..., k0=v0, k1=v1, ...)
6+
The arguments to the .format() method are of two types. The list starts with zero or more positional arguments pi, followed by zero or more keyword arguments of the form ki=vi, where each ki is a name with an associated value vi.
7+
```
8+
### Example
9+
```
10+
1.Here we could see that if there are are no values in the curly brackets it directly maps according to the position. And if there are are position given in the curly brackets then it maps them according to the given index.
11+
```
12+
![Code1](/images/F1.png)
13+
```
14+
2.If you want to shift a no to right then you can include the no of spaces required after the colon
15+
```
16+
![Code2](/images/F2.png)
17+
```
18+
3.For printing a no its square and its cube we can use the formatting techniques.
19+
```
20+
![Code3](/images/F3.png)
21+
```
22+
We could see the difference when we use the formatting tools. The 1st one uses formatting functions.
23+
```
24+
![Code4](/images/F4.png)
25+
```
26+
4.We can use it for rounding of some values to given decimal points.
27+
```

Diff for: Logging.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Logging
2+
```python
3+
When you transfer money, there are transfer records.
4+
If something goes wrong, people can read the log and has a chance to figure out what happened.
5+
Likewise, logging is important for system developing, debugging and running.
6+
When a program crashes, if there is no logging record, you have little chance to understand what happened.
7+
You can use the logging functions by just importing logging.
8+
```
9+
### Logging Levels
10+
```
11+
There are many logging levels.
12+
The numeric values of logging levels are given in the following table.
13+
These are primarily of interest if you want to define your own levels, and need them to have specific values relative to the predefined levels.
14+
If you define a level with the same numeric value, it overwrites the predefined value; the predefined name is lost.
15+
```
16+
|Level| Numeric value|
17+
|-----|------|
18+
CRITICAL|50
19+
ERROR|40
20+
WARNING|30
21+
INFO|20
22+
DEBUG|10
23+
NOTSET|0
24+
```python
25+
They are usually used with:
26+
logging.basciConfig(level=logging.DEBUG) Or
27+
logging.basciConfig(level=logging.INFO)
28+
```
29+
### Steps
30+
```python
31+
Create a file and enter the logging code and then run the code , output will appear on the shell.
32+
If you are using any file name like:
33+
logging.basicConfig(filename='example.log',level=logging.DEBUG)
34+
Then you can see your output in the file named ‘example’ .
35+
However the default level is WARNING
36+
```
37+
#### Case 1
38+
```python
39+
If no level was mentioned:
40+
It does not take the .info information
41+
```
42+
![Code1](/images/LO1.png)
43+
![Code2](/images/LO2.png)
44+
#### Case 2
45+
```python
46+
When level was debug, all the statements were executed.
47+
```
48+
![Code3](/images/LO3.png)
49+
![Code4](/images/LO4.png)
50+
```python
51+
Here we can see that logging is similar to print statements
52+
But..
53+
It works when the program is a simple script, but for complex systems, you better not to use this approach. First of all, you cannot leave only important messages in the log, you may see a lots of garbage messages in the log, but can’t find anything useful.You also cannot control those print statements without modifying code, you may forgot to remove those unused prints.
54+
55+
It can be used with some formatting functions also:
56+
```
57+
![Code5](/images/LO5.png)
58+
![Code6](/images/LO6.png)
59+

Diff for: images/A1.png

4.68 KB
Loading

Diff for: images/A2.png

3.12 KB
Loading

Diff for: images/A3.png

3.64 KB
Loading

Diff for: images/A4.png

5.35 KB
Loading

Diff for: images/A5.png

3.22 KB
Loading

Diff for: images/A6.png

5.03 KB
Loading

Diff for: images/A7.png

7.54 KB
Loading

Diff for: images/F1.png

10.3 KB
Loading

Diff for: images/F2.png

2.32 KB
Loading

Diff for: images/F3.png

11.3 KB
Loading

Diff for: images/F4.png

2.99 KB
Loading

Diff for: images/LO1.png

2.2 KB
Loading

Diff for: images/LO2.png

1.12 KB
Loading

Diff for: images/LO3.png

4.91 KB
Loading

Diff for: images/LO4.png

1.67 KB
Loading

Diff for: images/LO5.png

4.58 KB
Loading

Diff for: images/LO6.png

1.84 KB
Loading

0 commit comments

Comments
 (0)