Introduction to Python
AGENDA
• Python installation
• Vars
• Functions
• Conditional blocks (if, else)
• Loops
• File handling
• Class
• Objects
• Python for OSWE
Python Installation
Task Variables
• Explain what variables are in Python and how they are used. Create a
code snippet where you declare a variable named `temperature` and
assign it the value `25`. Then, update its value to `30` and print the
result.
Task Function
• Define a function in Python. Write a function named `calculate_area`
that takes two arguments, `length` and `width`, and returns the area
of a rectangle. Demonstrate how you would call this function with the
values `length=10` and `width=20` and print the result.
Conditional Blocks (if, else)
• Explain the purpose of conditional blocks in Python. Write a code
snippet that checks if a variable `age` is greater than 18. If it is, print
"Adult", otherwise print "Minor".
Loops
• Describe the difference between `for` loops and `while` loops in
Python. Write a `for` loop that iterates over a list of numbers from 1
to 5 and prints each number. Then, write a `while` loop that achieves
the same output.
File Handling
• Explain how file handling works in Python. Write a code snippet that
opens a file named `[Link]` in read mode, reads its contents,
and prints them to the console. Make sure your code properly
handles exceptions and closes the file whether an exception occurs or
not.
Class
• Describe what a class is in Python and how it is used. Create a class
named `Vehicle` with two attributes, `make` and `model`. Include an
initialization method that assigns values to these attributes when a
new `Vehicle` object is created.
Objects
• Explain the concept of objects in Python in relation to classes. Using
the `Vehicle` class defined in the previous task, create an object
named `my_vehicle` with `make='Toyota'` and `model='Corolla'`.
Demonstrate how to access the attributes of the `my_vehicle` object
and print them.
Python significance in OSWE
• Create simple web requests in python
• Create file upload web requests in python