0% found this document useful (0 votes)
10 views2 pages

Python Programming Essentials

The document provides an overview of essential Python programming concepts including lists, tuples, sets, dictionaries, functions, file handling, exception handling, list comprehension, classes, and lambda functions. Each concept is illustrated with code examples demonstrating their usage. This serves as a foundational guide for beginners in Python programming.

Uploaded by

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

Python Programming Essentials

The document provides an overview of essential Python programming concepts including lists, tuples, sets, dictionaries, functions, file handling, exception handling, list comprehension, classes, and lambda functions. Each concept is illustrated with code examples demonstrating their usage. This serves as a foundational guide for beginners in Python programming.

Uploaded by

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

Python Programming Essentials

1. List
fruits = ['apple', 'banana', 'cherry']
[Link]('mango')
print(fruits[1])

2. Tuple
dimensions = (1920, 1080)
print(dimensions[0])

3. Set
nums = {1, 2, 3, 3}
[Link](4)
print(nums)

4. Dictionary
person = {'name': 'John', 'age': 25}
person['city'] = 'New York'
print(person['name'])

5. Function
def greet(name):
return f"Hello, {name}!"

print(greet("Alice"))

6. File Handling
with open("[Link]", "w") as file:
[Link]("Hello, world!")

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


print([Link]())

7. Exception Handling
try:
x = int(input("Enter number: "))
print(10 / x)
except ZeroDivisionError:
print("Cannot divide by zero")

8. List Comprehension
squares = [x**2 for x in range(5)]
print(squares)
9. Class Example
class Student:
def __init__(self, name):
[Link] = name

def greet(self):
print(f"Hello, I'm {[Link]}")

s1 = Student("Alice")
[Link]()

10. Lambda Function


add = lambda x, y: x + y
print(add(5, 3))

You might also like