DEV Community

varatharajan
varatharajan

Posted on

Day 3 - Python

**

Built-in Data Types :
**
In programming, data type is an important concept.

Variables can store data of different types, and different types can do different things.

Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType

for example

no1 = 5
print(no1)
print(type(no1))

no2 = ("get a value from user")
print(no2)
print(type(no2))

no3 = 5.5
print(no3)
print(type(no3))

Enter fullscreen mode Exit fullscreen mode

result


5
<class 'int'>
get a value from user
<class 'str'>
5.5
<class 'float'>

Variables :
Variable is a reserved memory location to store values.

for example :

address = " 3, Kosakulam, madurai"
(reference variable
or
identifiers)

= ----> is called Assignment operator

Rules for Python variables:

  1. A variable name must start with a letter or the underscore character
  2. A variable name cannot start with a number
  3. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  4. Variable names are case-sensitive (age, Age and AGE are three different variables)
  5. Do not use any of Python's reserved keywords (e.g., for, if, while, etc.) as variable names.

( 1.Name should be meaningful.
bike_no = 1234
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 )

return
The return statement is used to exit a function and send a value back to the caller.

for example

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)


result1 = add(100,50)
result2 = subtract(50,25)
multiply(result1,result2)

Enter fullscreen mode Exit fullscreen mode

result
150
25
3750

pass :
The pass statement is used as a placeholder for future code.

example

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):
    pass


result1 = add(100,50)
result2 = subtract(50,25)
multiply(result1,result2)
divide(result1,result2)

Enter fullscreen mode Exit fullscreen mode

result
150
25
3750

Top comments (0)