Full stack python developer - day 3

lakshmi_prithanadesan_32

Lakshmi Pritha Nadesan

Posted on November 13, 2024

Full stack python developer - day 3

Data type:
Data type identifies the type of data that a variable can store.

1.String(str):
a="hello world"
a='hello world'

2.Number(int):
a=10

3.Float(float):
a=12.2

4.Boolean(bool):
a=True
b=False

Some other data types:

list, set, complex, tuple, range, dict, set, frozenset, bytes,bytearray, memoryview, nonetype.

Reference variable:
To create a variable in python is to assign it a value using assignment operator.

Syntax:
variablename=value

Example:
number=12

Rules to write variablename:

1.Name should be meaningful.
number,word
2.Space is not allowed.
bike_no,bikeNo
3.Number are allowed but not in first place.
age1
4.No special character is allowed except _ and $ symbol.
car_no1

pass:

pass statement is null operation that does nothing when executed.The pass statement is used for future code.

type():

It is a build in function that is used to return the type of data stored in the variables of the program.

return:

The return is keyword is to exit a function and return a value.

Example 1:

num1 = 10
print(num1)
print("Datatype of num1 is",type(num1))

num2 = 26.5
print(num2)
print("Datatype of num2 is",type(num2))

num3 = 2 + 6j
print(num3)
print('Datatype of num3 is',type(num3))

Enter fullscreen mode Exit fullscreen mode

Result:

10
Datatype of num1 is <class 'int'>
26.5
Datatype of num2 is <class 'float'>
(2+6j)
Datatype of num3 is <class 'complex'>
Enter fullscreen mode Exit fullscreen mode

Example 2:

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)
    return no1*no2

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

def modules(no1,no2):
    pass

result1=add(10,12)
result2=subtract(12,8)
result3=multiply(result1,result2)
result4=divide(result3,10)

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

Result:

22
4
88
8.8
50
<class 'int'>
0.5
<class 'NoneType'>
<class 'NoneType'>

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
lakshmi_prithanadesan_32
Lakshmi Pritha Nadesan

Posted on November 13, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related