0% found this document useful (0 votes)
16 views3 pages

Unit 1 Computational Thinking Python Notes

This document covers key concepts in Python programming, including functions, exception handling, file handling, binary files, CSV files, and the stack data structure. It details the types and syntax of functions, error management, file operations, and stack operations. The content is tailored for Class 12 students learning Python.

Uploaded by

Rahul Kumar
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)
16 views3 pages

Unit 1 Computational Thinking Python Notes

This document covers key concepts in Python programming, including functions, exception handling, file handling, binary files, CSV files, and the stack data structure. It details the types and syntax of functions, error management, file operations, and stack operations. The content is tailored for Class 12 students learning Python.

Uploaded by

Rahul Kumar
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

UNIT – 1: COMPUTATIONAL THINKING AND PROGRAMMING – 2

1. FUNCTIONS IN PYTHON
A function is a block of code that performs a specific task.

Types of Functions:
• Built-in Functions – print(), len(), type()
• Functions defined in module – [Link]()
• User defined functions

Syntax:
def function_name(parameters):
statements
return value

Types of Parameters:
• Positional Parameters
• Default Parameters

Scope of Variables:
• Local Variable
• Global Variable

2. EXCEPTION HANDLING
Exception is an error that occurs during execution.

Syntax:
try:
statement
except:
statement
finally:
statement

3. FILE HANDLING
Types of Files:
• Text File
• Binary File
• CSV File

Text File Operations:


• Open file
• Read / Write
• Append
• Close file

File Modes:
r, w, a, r+, w+, a+

Reading Methods:
read(), readline(), readlines()

seek() – moves cursor


tell() – returns cursor position

4. BINARY FILE
Binary files store data in binary format.

Uses pickle module:


dump() – write
load() – read

File Modes:
rb, wb, ab, rb+, wb+, ab+

5. CSV FILE
CSV – Comma Separated Values

Write:
[Link]()
writerow()
writerows()

Read:
[Link]()

6. STACK (DATA STRUCTURE)


Stack follows LIFO principle.

Operations:
• Push
• Pop
• Peek
• isEmpty()

Implementation using list:


[Link]()
[Link]()

----------------------------------
Prepared for Class 12 – Python

You might also like