0% found this document useful (0 votes)
15 views13 pages

Baskartech Academy Python

The document outlines a comprehensive agenda for a Python programming course, covering topics such as installation, data types, control structures, functions, and file handling. It includes definitions, syntax, examples, and hands-on questions to reinforce learning. The course is designed for both beginners and advanced users, emphasizing Python's versatility in various applications.

Uploaded by

tonybaskar83
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)
15 views13 pages

Baskartech Academy Python

The document outlines a comprehensive agenda for a Python programming course, covering topics such as installation, data types, control structures, functions, and file handling. It includes definitions, syntax, examples, and hands-on questions to reinforce learning. The course is designed for both beginners and advanced users, emphasizing Python's versatility in various applications.

Uploaded by

tonybaskar83
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
You are on page 1/ 13

BASKARTECH

ACADEMY

BASICS OF PYTHON
PROGRAMMING
🔹 Python Basics Agenda Topics

1. Introduction to Python

2. Installing Python and IDEs

3. Print statements and comments

4. Variables and data types

5. Type casting

6. Input and Output

7. Conditional statements (if, else, elif)

8. Loops (for, while, break, continue, pass)

9. Functions (definition, arguments, return values)

10. Lists, Tuples, Sets, Dictionaries

11. String manipulation and methods

12. File handling (read, write, open, with)

13. Error handling (try, except, finally)

14. Modules and importing

15. Using built-in modules (random, datetime, etc.)

16. Creating custom modules


1. Introduction to Python
• Python is a high-level, interpreted, and general-purpose
programming language known for its readability and simplicity.
• No need for compilation.
Dynamically typed.
Great for beginners and advanced users.
• Used in web development, AI, data science, etc.

2. Installing Python and IDEs


• Install Python from python.org
• Use IDEs like:
• VS Code
• Python IDLE
• PyCharm
• Jupyter Notebook
• Thonny

3.Print statements and comments


• 🔹 Definition: Used to display output on the screen and write
inline notes in code.

• 📌 Syntax:
print("message") # This is a comment

• 📌 Example:
print("Hello, Python!") # Output: Hello, Python!

4.Variables and Data Types


• 🔹 Definition: A variable stores data. Python data types include
int, float, str, bool, etc.

• 📌 Syntax:
variable_name = value

• 📌 Example:
name = "Alice" # str
age = 25 # int
price = 99.99 # float
is_active = True # bool

5.Type Casting
• 🔹 Definition: Converting one data type into another.

• 📌 Syntax:
int(), float(), str(), bool()

• 📌 Example:
a = int("5") # converts string to int
b = float("4.3") # converts string to float
c = str(100) # converts int to string

6. Input and Output


• 🔹 Definition: input() takes user input; print() shows output.

• 📌 Syntax:
input("message")
print(value)

• 📌 Example:
name = input("Enter your name: ")
print("Welcome", name)

7. Conditional Statements
• 🔹 Definition: Used to make decisions in the code.

• 📌 Syntax:
if condition:
# code
elif another_condition:
# code
else:
# code

• 📌 Example:

• num = 10 if num > 0: print("Positive") elif num == 0:


print("Zero") else: print("Negative")

8. Loops in Python (for, while, break, continue)

🔹 Definition:

Loops are used to execute a block of code repeatedly. Python


supports two main loops:

 for loop – used when you want to iterate over a sequence (like a
list, string, range, etc.).
 loop – used when you want to repeat code as long as a
while
condition is true.

Additional loop control keywords:

 break – exits the loop early.


 continue – skips the current iteration and moves to the next.

1. For Loop
🔹 Definition: Repeats a block of code for each item in a sequence.

📌 Syntax:

for variable in sequence:


# code block

📌 Example:

for i in range(5):
print(i)

📝 Output:

0
1
2
3
4

🔁 2. while Loop
🔹 Definition: Repeats a block of code as long as the condition is True.

📌 Syntax:

while condition:
# code block

📌 Example:
count = 0
while count < 5:
print(count)
count += 1

📝 Output:

3. break Statement
🔹 Definition: Exits the loop immediately, even if the loop condition is
still true.

📌 Syntax:

for i in range(10):
if i == 5:
break
print(i)

📝 Output:

0
1
2
3
4

🔁4 . continue Statement
🔹 Definition: Skips the current iteration and moves to the
next.
📌 Syntax:
for i in range(5):
if i == 2:
continue
print(i)

📝 Output:
0
1
3
4

🔄 Summary Table:

Keywor Purpose
d
for Loop through a sequence (list,
string, etc.)
while Loop while a condition is true
break Exit the loop
continue Skip the current iteration

9. Functions
• 🔹 Definition: Reusable block of code that performs a specific
task.
• 📌 Syntax:
def function_name(parameters): # code return value

• 📌 Example:
def greet(name): return "Hello " + name print(greet("Alice"))

10. Data Structures


• ✅ List:
• 🔹 Ordered, mutable collection.
• 📌 Syntax & Example:
fruits = ["apple", "banana"]
fruits.append("mango")
print(fruits[0])
• ✅ Tuple:
• 🔹 Ordered, immutable collection.
• 📌 Example:
coords = (10, 20)
print(coords[1])
• ✅ Set:
• 🔹 Unordered, unique elements.
• 📌 Example:
s = {1, 2, 3, 3}
s.add(4) print(s)
• ✅ Dictionary:
• 🔹 Key-value pairs.
• 📌 Example:
student = {"name": "Tom", "age": 21}
print(student["name"])

11. String Methods


• 🔹 Definition: Operations that can be performed on strings.
• 📌 Example:
text = "Hello Python"
print(text.upper()) # HELLO PYTHON
print(text.lower()) # hello python
print(len(text)) # 12
print("Python" in text) # True

12. File Handling


• 🔹 Definition: Reading and writing to files.
• 📌 Write Example:
with open("demo.txt", "w") as f: f.write("Hello File")
• 📌 Read Example:
with open("demo.txt", "r") as f: content = f.read()
print(content)

13. Exception Handling in Python


• 🔹 Definition:
Exception Handling is a method of handling runtime errors
(errors that occur while the program is running) without crashing the
program.

• Python provides the try, except, else, and finally blocks to manage
exceptions.

Example:

try:
num = int(input("Enter a number: "))
result = 10 / num
except ValueError:
print("Invalid input! Please enter a number.")
except ZeroDivisionError:
print("Can't divide by zero!")
else:
print("Result is:", result)
finally:
print("This runs no matter what.")

🔥 Common Built-in Exceptions:

Exception Description
ZeroDivisionErr Raised when dividing by zero
or
ValueError Raised when an invalid value is
used
TypeError Raised when a wrong type is
used
IndexError Raised when accessing invalid
index
KeyError Raised when a key is not in a
dict
FileNotFoundEr Raised when a file is not found
ror

14. Modules and Imports


• 🔹 Definition: Python files containing functions/classes that can be
reused.
• 📌 Syntax:
import module_name from module_name import item
• 📌 Example:
import math
print(math.sqrt(16))

15. Built-in Modules (random, datetime)


• 📌 Random Example:
import random
print(random.randint(1, 100))
• 📌 Datetime Example:
import datetime
print(datetime.datetime.now())

16. Custom Module Creation


• 📌 my_module.py:
def add(a, b):
return a + b
• 📌 main.py:
import my_module
print(my_module.add(5, 3))

Python Hands-On Questions

1. Variables and Data Types

🔸 Question: Create a program that stores your name, age, and is_student
status in variables. Print them all.

2. Operators

🔸 Question: Write a program to take two numbers and print the result of:

 addition
 subtraction
 multiplication
 division
 modulus

3. Input and Output

🔸 Question: Ask the user to enter their name and favorite programming
language. Print a greeting like:
Hello John! You love Python!

4. Conditional Statements

🔸 Question: Write a program that takes a number from the user and checks
whether it is positive, negative, or zero.
5. Lists and Tuples

🔸 Question: Create a list of 5 fruits. Print the third fruit, and also print all
fruits using a loop.

6. Loops (for, while, break, continue)

🔸 Question: Write a for loop to print numbers from 1 to 10. If the number is
5, skip it using continue. Stop the loop if the number is 8 using break.

7. Strings

🔸 Question: Ask the user to enter a word. Print:

 The word in uppercase


 Number of characters
 Whether the word starts with a vowel

8. Dictionaries

🔸 Question: Create a dictionary with keys: "name", "age", "course". Store your
info and print each key and value.

9. Functions

🔸 Question: Write a function called add_numbers(a, b) that returns the sum of


two numbers. Call the function with different values.

10. Classes and Objects

🔸 Question: Create a class Student with attributes name and grade. Add a
method display() to print student details. Create an object and call the
method.
11. Exception Handling

🔸 Question: Write a program that takes two numbers from the user and
divides them. Use try-except to catch a division by zero error.

12. File Handling

🔸 Question: Write a program to:

1. Create a file called info.txt


2. Write "Hello from Python!" into it
3. Then read and print the content

You might also like