Python Front Page
Python Front Page
Python Front Page
ABC :
EX:
>>> print("Hello World!")
Hello World!
1.integer(int)
3.complex numbers
Ex:
>>>mylist=[‘abcd’,20.5,(2+3J),0.05]
Methods
1. insert(index,obj) 7.Slicing
2.append() 8.sort()
3. Access 9. reverse()
6. Update or Assign
TUPLES
Lists Tuples
Is different from sequence type containers like lists and tuples in the
way the data is stored and accessed
>>> dict1['name']='john‘
>>> dict1['branch']='CSE'
>>> dict1['subject']='PYTHON'
>>> dict1
{'subject': 'PYTHON', 'branch': 'CSE', 'name': 'john'}
---- assigning variables to the dictionary
Types of Operators
1. Arithmetic Operators
2. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
Loops
nested loops You can use one or more loop inside any another
while, or for loop.
Decision Making
•Decision-making is the expectation of conditions occurring
during the execution of a program and specified actions taken
according to the conditions.
The Loop control statements change the execution from its normal
sequence.
When the execution leaves a scope, all automatic objects that were
created in that scope are destroyed.
Python supports the following control statements.
break statement
Terminates the loop statement and transfers execution to the
statement immediately following the loop.
continue statement
Causes the loop to skip the remainder of its body and immediately
retest its condition prior to reiterating.
pass statement
The pass statement in Python is used when a statement is required
syntactically but you do not want any command or code to
execute.
A function is
int fact(int n)
{
if(n==1)
Definition
return n
else
return(n*fact(n-1))
1. Required arguments
2. Keyword arguments
3. Default arguments
4. Variable-length arguments
The Anonymous Functions
•can take any number of arguments but return just one value
in the form of an expression.
Example
# Function definition is here
sum = lambda arg1, arg2: arg1 + arg2
result −
Value of total : 30
Value of total : 40
Function vs. Procedure:
•Global variables
•Local variables
Module :
sum.py −
def sumab():
a=int(input("Enter First Number: "))#20
b=int(input("Enter Second Number: "))#10
return a+b
The import Statement
1. _ _import_ _()
2. dir()
4. reload()
Overview of OOP Terminology
class ClassName:
'Optional class documentation string'
class_suite
Error---
syntax:
Syntax:
assert expression[,args]
Exception
StandardError SystemError