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

Python Particulars Class12

Uploaded by

ahmad7902938
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)
7 views3 pages

Python Particulars Class12

Uploaded by

ahmad7902938
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
You are on page 1/ 3

Python Particulars for Class 12

1. Data Types:

- Numbers: int, float, complex

- String: Sequence of characters (e.g., "Hello")

- List: Ordered collection of elements (e.g., [1, 2, 3])

- Tuple: Immutable ordered collection (e.g., (1, 2, 3))

- Dictionary: Key-value pairs (e.g., {"name": "Ayesha", "age": 18})

- Set: Unordered collection of unique elements (e.g., {1, 2, 3})

2. Conditional Statements:

- if statement:

num = 10

if num > 0:

print("Positive")

- if-else statement:

num = -5

if num > 0:

print("Positive")

else:

print("Negative")

- elif statement:

num = 0
if num > 0:

print("Positive")

elif num == 0:

print("Zero")

else:

print("Negative")

3. Loops:

- For loop:

for i in range(1, 6):

print(i)

- While loop:

i=1

while i <= 5:

print(i)

i += 1

4. Functions:

def greet(name):

return "Hello, " + name

print(greet("Ayesha"))

5. Modules and Libraries:

import math
print(math.sqrt(16))

6. File Handling:

- Writing to a file:

file = open("data.txt", "w")

file.write("Hello, Class 12!")

file.close()

- Reading from a file:

file = open("data.txt", "r")

content = file.read()

print(content)

file.close()

7. Exception Handling:

try:

num = int(input("Enter a number: "))

print("Number is", num)

except ValueError:

print("Invalid input! Please enter a number.")

You might also like