# Code convention and key word argument
###### tags: `coderschool` `coding convention` `key word argument` `end` `sep`
[TOC]
### 1. Code convention
* Should have 2 lines under Import library
* Function name /variable : camelCase or snake_case
* The class name: PascalCase
* The constant:LIMIT_RATE
* The indentation should be 4 whitespaces.
* Doc string is written under the def function to explain the function Open by """ """.
* The explanation for the code in same line should use 2 whitespaces next to the code.
https://www.python.org/dev/peps/pep-0008/
### 2. Function with key-world argument **kwargs
#### a. Syntax:
`def function_name(arg,*arg,kwarg = "VALUE")`
#### b. Usage:
Using key-world argument WHEN WE DONT KNOW HOW MANY ELEMENT WILL BE CALLED and when adding more argument.
Python also priorise the argument before get the key-word. Therefore, Define the arguments in order .arg --> *arg --> key-word argument.
###### *arg:
also used with iterable to unpack a iteration.
```python=
x = (1, 2, 3)
>>> print(*x)
```
##### **kwarg:
We can provide a default value to an key world argument by using the assignment operator (=).
```python=
def foo(a=0, b=1):
return a + b
>>> foo()
1
>>> foo(1, 2)
3
>>> foo(b=3, a=4)
7
```
Usually used when we even dont put any argument to call the function
It is also used to in dictionary.
```python=
def foo(**kwargs):
for key, value in kwargs.items():
print(key, value)
foo(a=1, b=2)
a 1
b 2
```
### 3. The end parameter VS The sep parameter in print statement
* The end parameter is used to append any string at the end of the output of the print statement
```python
print("Studytonight", end=' ')
print("is awesome")
# Output:
Studytonight is awesome
```
* 'Sep' arguments passed to the program can be separated by different values.
EX1:
```python=
`print("Study", "tonight", sep = ' & ')
#Study & tonight ``
```
EX2:
```python=
print("Studytonight","has","been","created","for", sep = " _ ", end=" _STUDENTS")
#Output:
Studytonight _ has _ been _ created _ for _STUDENTS
```
**NOTE:**
%%time : to see how long it takes to execute the code