0% found this document useful (0 votes)
17 views4 pages

Class 12 Python Revision Guide

Uploaded by

vikramjha28.02
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Class 12 Python Revision Guide

Uploaded by

vikramjha28.02
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

REVISION SHEET – CLASS 12 CBSE

PYTHON REVISION TOUR – I & II

WORKING WITH FUNCTIONS • USING PYTHON LIBRARIES • FILE HANDLING

---------------------------------------------------------

PYTHON REVISION TOUR – I

---------------------------------------------------------

• Python is an interpreted, high-level, object■oriented language.

• Case-sensitive, indentation-based.

Data Types: int, float, bool, str, list, tuple, dict, set

Operators:

• Arithmetic: + - * / // % **

• Relational: < > <= >= == !=

• Logical: and or not

• Assignment: = += -= *=

• Membership: in, not in

• Identity: is, is not

Input & Output:

name = input("Enter name:")

age = int(input("Enter age:"))

print(name, age)

Conditional Statements:

if, elif, else

Loops:

for loop, while loop

Loop control: break, continue, pass

---------------------------------------------------------

PYTHON REVISION TOUR – II

---------------------------------------------------------

List Functions: append(), insert(), pop(), remove(), sort(), reverse()

String Methods: upper(), lower(), find(), replace(), split(), join()

Tuples: Ordered & immutable


Dictionary:

d = {"name": "Amit", "age": 17}

Keys(), values(), items(), update()

Modules:

import math

from math import sqrt

---------------------------------------------------------

WORKING WITH FUNCTIONS

---------------------------------------------------------

Function Syntax:

def function_name(parameters):

statements

return value

Types of Functions:

• Without parameters, without return

• With parameters, without return

• Without parameters, with return

• With parameters, with return

Example:

def add(a, b):

return a + b

Default Arguments:

def fun(a=10, b=5):

Keyword Arguments:

fun(b=20, a=5)

Variable Length Arguments:

def total(*num):

Global & Local Variables:

x = 10 # global

def test():

y = 5 # local
---------------------------------------------------------

USING PYTHON LIBRARIES

---------------------------------------------------------

Common Libraries:

• math – sqrt(), ceil(), floor()

• random – randint(), choice(), random()

• statistics – mean(), median(), mode()

• datetime – date, time, datetime classes

Example:

import math

print([Link](49))

---------------------------------------------------------

FILE HANDLING

---------------------------------------------------------

Opening Files:

open("filename", "r") # read

open("filename", "w") # write

open("filename", "a") # append

Reading Files:

[Link]()

[Link]()

[Link]()

Writing Files:

[Link]("Hello")

Closing File:

[Link]()

Using with-statement:

with open("[Link]", "r") as f:

data = [Link]()

Exception Handling:

try:
a = 10/0

except ZeroDivisionError:

print("Error")

finally:

print("Done")

---------------------------------------------------------

END OF REVISION SHEET

---------------------------------------------------------

You might also like