June 7
June 7
=> Any number which is preceded by "0x" or "0X" is treated as a hexadecimal value
Eg: 0x12cd, 0X12CD...
a = 100 # decimal
b = 0b100 # binary
c = 0o100 # octal
d = 0X100 # hexa-decimal
------------------------------------------------
# Number Systems in Python
a = 100 # decimal
b = 0b100 # binary
c = 0o100 # octal
d = 0X100 # hexa-decimal
===================================================================================
======
Object:
== Properties(data)
== Behavior(methods)
Eg:
Employee:Object
== Properties => emp_id,emp_name,salary....
== Behavior => read(), print(), update() ....
Eg:
Account:Object
== Properties => acc_id, acc_type, balance....
== Behavior => create(), withdraw(), showBalance() ....
-------------------------------------------
Functions vs Methods:
Functions:
== Not a member of any object
== Call be called directly
Eg: print(), int(), eval(), input() ....
Methods:
== Member of some object
== Can be called only through objects
Eg: str => lower(), upper(), title()....
list => append(), extend(), ....
------------------------------------------
Functions in Python :
=====================
=>A function is a self-contained block of statements designed to perform a specific
task. They are also called "sub-programs".
-> To overcome the above limitations,we can use functions. Using functions, the
statements to be executed are written only once, but can be "called and executed"
wherever required.
NOTE :
1) Parameters are the values that are passed as an input to a function. They are
also called "Arguments".
2) A function can accept any no. of parameters,but can return only one value at a
time.
3) If a function does not accept any parameters,we can keep the braces empty
def add(a,b):
c = a + b
return c
def add(a,b):
c = a + b
print("Additon : ",c)
add(10,20)
add(100,200)
add(12.5,22.5)
--------------------------------------
# creating a function without parameters and with return value
def add():
a = int(input("Enter first value : "))
b = int(input("Enter second value : "))
c = a + b
return c
z = add()
print("sum : ",z)
----------------------------------------
# creating a function without parameters and without return value
def add():
a = int(input("Enter first value : "))
b = int(input("Enter second value : "))
c = a + b
print("Sum : ",c)
add()
------------------------------------------
# creating a function without parameters and without return value
def display():
print("I am from Display Function")
display()
display()
------------------------------------------------