Python 100 days challenge : Day-2

·

3 min read

Today we will learn about variables, data types, and operators.

Variables: We use variables to store values.

Ex:

name = "John"
age = 45

Here, name and age are variables. As we discussed on day-1 in python, we need not declare the variable type, based on the value that we assign to the variable system automatically assign the data type. Hence, we call Python as a dynamically typed language

Data types:: Type of value that variable has.

Python has different data types, let's discuss a few. As we progress, we will understand the other data types as well.

Number type: Int(integer), Float, complex

int(Integer) type: Store only numbers without decimals

Float type " Store numbers with decimals

Complex type: Complex numbers are written in the form, x + yj, where x is the real part and y is the imaginary part.

Text type: str (string)

ex:

# is used in python for commenting, which means, this will not be printed into the console, we will use these comments for understands the operations that we perform.

name = "Sam"         #name is a string data type.
age = 50                  # age is a integer data type
income = 50.5         # income is a float data type
#Complex number
a = 10
b = 20
c = complex(a,b)    # We use complex function to get a complex value.

Output : 10=20j

image.png

Python operators: We use these operators to perform some action on variables and values. Click here to know more details on operators

Operator types:

  • Assignement operators
  • Arithmetic operators
  • Comparision operators
  • Logical operators
  • Identity operators
  • membership operators
  • bitwise operators
  • Assignment operators: We use these operators to assign value to variables.

    ex :

    name = "John"      # here "=" is an assignment operator as we are assigning John to name variable.
    

    Arithmetic operators: : We use these operators to perform some mathematical operations like addition, subtraction, division, etc.

    ex:

    Add = 5 + 5      #Here + is a arithmetic operator
    

    Comparision operators: : We use these operators to compare values, like less than, great than, equals to, etc.

    ex:

    "x" == "y"      #Here == will compare whether x & y are equal or not.
    

    Python Logical Operators: We use these operators to combine conditional statements.

    ex:

    40 > 50  or 50 > 60  #Here "or" Returns True if one of the statements is true.
    40 > 50  and 50 > 60   #Here "and" Returns True if both statements are true.
    
    not (40 > 50  and 50 > 60) #Here "not" reverses the result. If the result is true we get false, if the result is false we get true.
    

    Python Membership Operators: We use these operators to check if a sequence is presented in an object.

    ex: ``` M in K # Here "in" Returns True if a sequence with the specified value is present. M not in K # Here "not in" Returns True if a sequence with the specified value is not present.

    Python Bitwise Operators: We use these operators to compare (binary) numbers.