DEV Community

Kuhanraja A R
Kuhanraja A R

Posted on

1

Day 4 at payilagam "Introduction to functions"

some new git commands:
git branch (branch_name)
git checkout (Branch_name)
git add
git commit -m"message"
git push
git push -set--upstream origin branch_name
git merge branch_name

discussion about variable and object:

In python, variable is an object. Is it so? In python, everything is an object. Python is strongly object oriented programming language.

Object - Real time entity, Physical Entity, Real life entity
Class - Logical entity, Template, Blueprint.

Object represents class
Object is sample of class
object is instance of class

object cannot be present without class - True or False

Class can be present without object - True or False

Python is a dynamically typed programming language.

duck typed programming language:
python sarcastically says other programming languages as duck typed programming language. because python doesn't specify any kind of datatypes. but other languages like c insist to put the data type. so it is called as duck typed programming.

Python functions:
def add (no1, no2)
print(no1 + no2)

def --> definition
add --> Function name
no1, no2 --> Arguments/parameters
Arguments/Parameters : Inputs given to a function

eating(food)


def add (no1,no2):
    print(no1+no2)

def subtract(no1,no2):
    print(no1-no2)

def multiply(no1,no2):
    print(no1*no2)

def divide(no1,no2):
    print(no1/no2)

def find_power(no1,no2):
    print(no1**no2)
    pass

add(20,10)
subtract(20,10)
multiply(2,3)

output:
30
10
6
Enter fullscreen mode Exit fullscreen mode

Task:
Types of arguments:

Default argument

Default Arguments is a parameter that have a predefined value if no value is passed during the function call. This following example illustrates Default arguments to write functions in Python.

Keyword arguments

Keyword arguments are passed by naming the parameters when calling the function. This lets us provide the arguments in any order, making the code more readable and flexible.

Positional arguments

Positional arguments in Python are values that we pass to a function in a specific order. The order in which we pass the arguments matters.

This following example illustrates Positional arguments to write functions in Python.

Arbitrary arguments (variable-length arguments args and kwargs)

In Python Arbitrary arguments allow us to pass a number of arguments to a function. This is useful when we don't know in advance how many arguments we will need to pass. There are two types of arbitrary arguments:

args in Python (Non-Keyword Arguments):

Collects extra positional arguments passed to a function into a tuple.

kwargs in Python (Keyword Arguments):

Collects extra keyword arguments passed to a function into a dictionary.

Lambda Function Arguments:

Lambda functions work like regular functions, taking arguments to perform task in one simple expression. we can pass any number of arguments. Here are the common ways to pass arguments in lambda function:

-->Single Argument

-->Multiple Arguments

newly learnt:
anaconda
jython

Neon image

Serverless Postgres in 300ms (!)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free →

Top comments (0)

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay