DEV Community

Kuhanraja A R
Kuhanraja A R

Posted on

python session day 3 at payilagam

data type - mentioning what type of data is it
name = 'raja' -> string data type
num = 1 -> integer data type
num = 2.2 -> float data type

boolean data type : True or False
ex: raining = False

in python it boolean data type is denoted as bool.
integer and float adds negative num also.

address = '5/2A, South Street, Madurai.'

Here,
address -> variable
= -> assignment operator
'5/2A,South Street, Madurai,' -> values

reference variable - Identifiers(The name given for a variable)

How can we write identifiers
1) Meaning full names
2) No space allowed
3) Numbers are allowed, but not in first.
4) No special character is allowed, except _ and $

Return data types :
From the previous day, we are going to define a function

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)

no1 = 10
no2 = 12
add(no1, no2)
subtract(no1, no2)
Enter fullscreen mode Exit fullscreen mode

whatever we are calling it only derived as output.


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

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

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


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

no1 = 10
no2 = 12
r1 = add(no1, no2)
r2 = subtract(no1, no2)
multiply(r1,r2)
Enter fullscreen mode Exit fullscreen mode

in this case we are returned the values of the function.
so it multiplies lies (the answer of add * the answer of subtract)

type function is used to denote which data type is used.

print(type(subtract(100,50)))
print(type(multiply(10,20)))
Enter fullscreen mode Exit fullscreen mode

In this case the first on gives answer as 50 and it gives the data type as int.

but in case of multiply the value has not returned so, it simply says none type.

Top comments (1)

Collapse
 
payilagam_135383b867ea296 profile image
Payilagam

Title of this page would be better, if we have similar to --> Python Datatypes, Functions - Payilagam