DEV Community

Kiruthiga S
Kiruthiga S

Posted on

Python

Operators
Operators are used to perform operations on variables and values

Arithmetic Operators
Used to perform basic mathematical operations like addition, subtraction, multiplication and division

a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a % b)
print(a ** b)
print(a // b)
Enter fullscreen mode Exit fullscreen mode

Output:Enter first number:10
Enter second number:20
30
-10
200
0.5
10
100000000000000000000
0

Comparison Operators
Comparison or relational operators that compares the value and returns whether the condition is true or false

a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
print(a > b)
print(a < b)
print(a == b)
print(a != b)
print(a >= b)
print(a <= b)
Enter fullscreen mode Exit fullscreen mode

Output:Enter first number:10
Enter second number:2
True
False
False
True
True
False

Logical Operators
Perform Logical AND, Logical OR and Logical NOT operations

a = True
b = False
print(a and b)
print(a or b)
print(not a)
Enter fullscreen mode Exit fullscreen mode

Output:False
True
False

Assignment Operators
Used to assign values to variables

a = 10
a += 5
print(a)
a -= 5
print(a)
a *= 5
print(a)
a <<= 1
print(a)
a >>= 1
print(a)
Enter fullscreen mode Exit fullscreen mode

Output:15
10
50
100
50

Ternary Operator
Allows to assign one value if a condition is true, and another if it is false

a, b = 10, 20
min = a if a < b else b

print(min)
Enter fullscreen mode Exit fullscreen mode

Output:10

What is Run time?
Runtime means the time when a computer program is actively running, or the software environment that lets it run
Runtime is when the finished program actually performs its tasks for the user

What is Compile time?
Compile time is the period when a compiler program translates human-readable source code into machine-readable binary code, syntax and semantic checks occur, and compile-time errors are found

What is System Language?
System Language is a 0's and 1's (signals)

Function
Function is reusable blocks of code
function can be defined using def keyword

def function_name(parameters):
Enter fullscreen mode Exit fullscreen mode

*Function Calling *

def fun():
    print("Welcome To Python")

fun()
Enter fullscreen mode Exit fullscreen mode

Output:Welcome To Python

*Function calling with parameter *

def fun(a):
    print(a+ "Welcome To Python")

fun("Hello")
Enter fullscreen mode Exit fullscreen mode

Output:HelloWelcome To Python

Function with return

def evenOdd(x):
    if (x % 2 == 0):
        return "Even"
    else:
        return "Odd"

print(evenOdd(4))
print(evenOdd(5))
Enter fullscreen mode Exit fullscreen mode

Output:Even
Odd

Top comments (0)