DEV Community

lordronjuyal
lordronjuyal

Posted on

day 06

date:- 25 May, 2024.

Function:- We can pass data into the function and can then use it there. To use this we have to define function parameters (variables especially for that function). Syntax is- def func_name( parameter1, parameter2):
Now we have to call the function and pass value, syntax for that is- func_name( argument1, argument2)
Order is important here. Parameter is the name of the variable and arguments are the values. We can also specify which argument to which parameter at the time of calling the function.
eg func_name(parameter2=argument2, parameter1=argument1):
Order in this case doesn't matter.

Dictionary:- It's a data structure in which we store data in key-value pairs. Each key needs to be unique. Value can be another data structure.

Syntax- dic = {key1 : value1 , key2 : value2, }
empty dic = {} # same thing can be used to clear a dictionary
to access a value- dic[key] # we need to know key
to add a key or change previous key's value- dic[key]=value
to delete a key- del dic[key]
to loop- 1) for key in dic:
2) for key, value in dic.items():

Functions I learned:-

  1. math.ceil(x) - this will return the smallest integer greater than or equal to x. eg it will change 5.2 t0 6. round will return 5 in this case. We have to import math module for this.
  2. math.sqrt(x) - it will return square root of x.
  3. sum(list) - Gives sum of the list, provided all items are numbers.
  4. list.index(item) - This will return the index(base 0) of the item if present in the list. It will only return the index of the first item it will find from the left if multiple are present. Also, if the item is not found it will cause an error, so better check with - if item in list: in the first place.

Programs I made:
1) Prime number checker (between 1 to 100):
Prime number checker

Top comments (0)