Python Programming Internship and Training Report
Divyansh Srivastava
Software Developer Intern at Metagates Innovation || SIH 2024 Finalist #Runner_Up || Penultimate Year Student of B.Tech at ITM GIDA Gkp. || CSE(AI/ML) Branch
Presenting my Python Training/Internship Report with OctaNet Services Pvt Ltd.
Offer Letter:
Table of Contents
1. Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and readability. It was created by Guido van Rossum and first released in 1991. Python is open-source and has a large community, making it a versatile tool for many programming tasks including web development, data analysis, artificial intelligence, and scientific computing.
Key Features:
2. Python Syntax and Semantics
Hello World:
The simplest Python program prints "Hello, World!" to the console.
print("Hello, World!")
Comments:
Comments are used to explain code. Single-line comments start with #, and multi-line comments are enclosed in triple quotes (''' or """).
# This is a single-line comment
"""
This is a
multi-line comment
"""
3. Variables and Data Types
Variables:
Variables are used to store data. Python's variables do not require explicit declaration to reserve memory space.
x = 10
y = 3.14
name = "Alice"
is_student = True
Data Types:
a = 10 # int
b = 3.14 # float
c = "Hello" # str
d = True # bool
e = None # NoneType
4. Basic Operations
Arithmetic Operators:
Perform mathematical operations.
x = 10
y = 3
print(x + y) # Addition: 13
print(x - y) # Subtraction: 7
print(x * y) # Multiplication: 30
print(x / y) # Division: 3.33
print(x // y) # Floor Division: 3
print(x % y) # Modulus: 1
print(x ** y) # Exponentiation: 1000
Comparison Operators:
Compare values and return a boolean.
a = 10
b = 20
print(a == b) # False
print(a != b) # True
print(a > b) # False
print(a < b) # True
print(a >= b) # False
print(a <= b) # True
Logical Operators:
Combine conditional statements.
a = True
b = False
print(a and b) # False
print(a or b) # True
print(not a) # False
5. Control Structures
Conditional Statements:
Execute code based on conditions.
x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
Loops:
For Loop:
Iterates over a sequence.
for i in range(5):
print(i) # 0 1 2 3 4
While Loop:
Repeats as long as a condition is true.
count = 0
while count < 5:
print(count)
count += 1 # 0 1 2 3 4
6. Functions
Functions are reusable blocks of code that perform a specific task.
Defining a Function:
def greet(name):
return f"Hello, {name}!"
Calling a Function:
message = greet("Bob")
print(message) # Outputs: Hello, Bob!
Parameters and Arguments:
Functions can accept parameters and return values.
def add(a, b):
return a + b
result = add(5, 3)
print(result) # Outputs: 8
Lambda Functions:
Anonymous functions defined with the lambda keyword.
square = lambda x: x ** 2
print(square(5)) # Outputs: 25
7. Collections
Python provides several built-in collection data types for managing groups of data.
List:
Ordered, mutable, and allows duplicate elements.
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
print(fruits) # Outputs: ['apple', 'banana', 'cherry', 'orange']
Tuples:
Ordered, immutable, and allows duplicate elements.
point = (10, 20)
print(point) # Outputs: (10, 20)
Sets:
Unordered, mutable, and does not allow duplicate elements.
unique_numbers = {1, 2, 3, 2}
print(unique_numbers) # Outputs: {1, 2, 3}
Dictionaries:
Unordered, mutable, and stores data in key-value pairs.
student = {"name": "Alice", "age": 21}
print(student["name"]) # Outputs: Alice
8. Object-Oriented Programming (OOP)
OOP is a programming paradigm based on the concept of "objects," which can contain data and code to manipulate that data.
Classes and Objects:
Example:
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
def bark(self):
return f"{self.name} says woof!"
# Create an object
my_dog = Dog("Rex", 5)
print(my_dog.bark()) # Outputs: Rex says woof!
Inheritance:
Inheritance allows a class to inherit attributes and methods from another class.
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
raise NotImplementedError("Subclasses must implement this method")
class Dog(Animal):
def speak(self):
return f"{self.name} says woof!"
class Cat(Animal):
def speak(self):
return f"{self.name} says meow!"
# Create objects
dog = Dog("Rex")
cat = Cat("Whiskers")
print(dog.speak()) # Outputs: Rex says woof!
print(cat.speak()) # Outputs: Whiskers says meow!
Encapsulation:
Encapsulation restricts access to certain components of an object.
class Person:
def __init__(self, name, age):
self.__name = name # Private attribute
self.__age = age # Private attribute
def get_name(self):
return self.__name
def get_age(self):
return self.__age
person = Person("Alice", 30)
print(person.get_name()) # Outputs: Alice
Polymorphism:
Polymorphism allows methods to be used interchangeably between different object types.
class Bird:
def speak(self):
return "Chirp!"
class Duck(Bird):
def speak(self):
return "Quack!"
# Create objects
bird = Bird()
duck = Duck()
# Polymorphism
for animal in [bird, duck]:
print(animal.speak()) # Outputs: Chirp! Quack!
9. File Handling
Python provides built-in functions for reading and writing files.
Reading Files:
with open('example.txt', 'r') as file:
content = file.read()
print(content) # Outputs the content of example.txt
Writing Files:
with open('example.txt', 'w') as file:
file.write("Hello, file!")
Appending to Files:
with open('example.txt', 'a') as file:
file.write("\nAppending new line.")
10. Modules and Packages
Introduction to Modules:
Modules are files containing Python code that can define functions, classes, and variables. They can also include runnable code. Using modules helps in organizing your code into manageable sections and promotes code reuse.
Importing Modules
You can import a module using the import statement.
import math
print(math.sqrt(16)) # Outputs: 4.0
Importing Specific Attributes
You can import specific attributes from a module using the from keyword.
from math import pi, sqrt
print(pi) # Outputs: 3.141592653589793
print(sqrt(25)) # Outputs: 5.0
Aliasing
Modules can be aliased using the as keyword.
import numpy as np
array = np.array([1, 2, 3])
print(array) # Outputs: [1 2 3]
Creating a Module
A module is simply a Python file with a .py extension.
# my_module.py
def greet(name):
return f"Hello, {name}!"
You can use the module in another file by importing it.
# main.py
import my_module
message = my_module.greet("Alice")
print(message) # Outputs: Hello, Alice!
Introduction to Packages:
A package is a way of organizing related modules into a directory hierarchy. A package must contain an __init__.py file.
Creating a Package
Directory structure:
mypackage/
__init__.py
module1.py
module2.py
Using a Package:
from mypackage import module1, module2
11. Exception Handling
Introduction to Exception Handling:
Exception handling is a mechanism to handle runtime errors, ensuring the flow of the program can continue or gracefully terminate.
Try-Except Block
Handle exceptions using a try-except block.
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")
Catching Specific Exceptions
You can catch specific exceptions and handle them differently.
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")
except TypeError:
print("Invalid type!")
Finally Block
The finally block is executed regardless of whether an exception occurred or not.
try:
file = open('example.txt', 'r')
content = file.read()
except FileNotFoundError:
print("File not found!")
finally:
file.close()
print("File closed.")
Raising Exceptions
You can raise exceptions using the raise keyword.
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero!")
return a / b
try:
print(divide(10, 0))
except ValueError as e:
print(e) # Outputs: Cannot divide by zero!
12. Advanced Topics
List Comprehensions:
List comprehensions provide a concise way to create lists.
squares = [x ** 2 for x in range(10)]
print(squares) # Outputs: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Generators:
Generators are functions that return an iterable set of items, one at a time, using the yield keyword.
def count_up_to(max):
count = 1
while count <= max:
yield count
count += 1
counter = count_up_to(5)
print(next(counter)) # Outputs: 1
print(next(counter)) # Outputs: 2
Decorators:
Decorators are functions that modify the behavior of other functions.
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
Context Managers:
Context managers allow you to allocate and release resources precisely when you want.
with open('example.txt', 'r') as file:
content = file.read()
print(content)
# The file is automatically closed after the block
Multithreading and Multiprocessing:
Python provides support for concurrent execution of code.
Multithreading:
import threading
def print_numbers():
for i in range(5):
print(i)
thread = threading.Thread(target=print_numbers)
thread.start()
thread.join()
Multiprocessing:
import multiprocessing
def print_numbers():
for i in range(5):
print(i)
process = multiprocessing.Process(target=print_numbers)
process.start()
process.join()
13. My Task (To Build an ATM Interface):
Source Code:
1. Importing the Time Module
import time
2. Printing Header Lines
print("======================================================")
print("======================================================")
3. Defining and Printing the Welcome Logo
welcome_logo = """
............
"""
print(welcome_logo)
4. Printing Footer Lines
print("======================================================")
print("======================================================")
5. Prompting User to Insert Card
print("\n====------------------------- Please inert your Card ---------------------------====")
time.sleep(5)
6. Setting the ATM PIN and Initial Balance
password = 1010
balance = 10000
7. Asking User for PIN Input
pin = int(input("\n\tEnter your ATM PIN: "))
8. Verifying the PIN
if pin == password:
9. Displaying the ATM Menu
while True:
print('''
1 : Check Balance
2 : Withdraw
3 : Deposit
4 : Exit
''')
10. Handling User Selection with Exception Handling
try:
option = int(input("\tPlease select any one option: "))
11. Checking Balance Option
if option == 1:
print("___________________________________________________________")
print("***********************************************************")
print(f"\n\tYour current balance is {balance}")
print("___________________________________________________________")
print("***********************************************************")
12. Withdraw Option
if option == 2:
withdraw_amount = int(input("\n\tPlease enter your Withdraw Amount: "))
balance = balance - withdraw_amount
print("___________________________________________________________")
print("***********************************************************")
print(f"\t{withdraw_amount} is debited from your account")
print("___________________________________________________________")
print("***********************************************************")
print("===========================================================")
print("___________________________________________________________")
print("***********************************************************")
print(f"\tYour update current balance is {balance}")
print("___________________________________________________________")
print("***********************************************************")
13. Deposit Option
if option == 3:
deposit_amount = int(input("\n\tPlease enter your Deposit Amount: "))
balance = balance + deposit_amount
print("___________________________________________________________")
print("***********************************************************")
print(f"\t{deposit_amount} is credited to your account")
print("___________________________________________________________")
print("***********************************************************")
print("======================================================")
print("___________________________________________________________")
print("***********************************************************")
print(f"\tYour updated current balance is {balance}")
print("___________________________________________________________")
print("***********************************************************")
14. Exit Option
if option == 4:
break
15. Handling Invalid Input
except:
print("\tPlease enter a valid option between 1 to 4")
16. Incorrect PIN Handling
else:
print("\n\tPIN inserted by you is not correct")
Output:
14. Conclusion
In conclusion, Python is a versatile and powerful programming language that offers a wide range of functionalities for developers of all levels. Its simplicity and readability make it an ideal choice for beginners, while its extensive libraries and frameworks make it suitable for complex applications and advanced users. Throughout this training and internship, we have explored various aspects of Python, from basic syntax and data types to more advanced topics such as object-oriented programming and file handling.
Key Takeaways
Practical Experience
The hands-on experience gained during this training and internship has provided a solid foundation in Python programming. By working on real-world projects and solving practical problems, we have developed a deeper understanding of how to apply Python in various contexts. This experience will undoubtedly be valuable in future endeavors, whether in academic pursuits or professional careers.
Future Prospects
As Python continues to evolve and grow in popularity, mastering this language opens up numerous opportunities in the tech industry. Its applications in emerging fields such as machine learning, data science, and automation ensure that Python skills will remain in high demand. Continuous learning and staying updated with the latest advancements in Python and its ecosystem will be crucial for leveraging its full potential.
In summary, Python is not just a programming language but a gateway to endless possibilities in technology and innovation. The knowledge and skills acquired during this training and internship form a strong foundation for future success and growth in the world of programming and beyond.
Internship Completion Certificate:
During this internship, I had the opportunity to:
?? Enhance my Python programming skills
?? Work on real-world projects
?? Collaborate with a talented team of developers
?? Learn and implement best practices in software development
I am grateful to OctaNet Services Pvt Ltd. for providing this valuable learning experience and for the certificate of completion. This internship has significantly boosted my confidence and technical expertise, and I am eager to apply these skills to future projects.A big thanks to my mentors and colleagues who supported me throughout this journey. Looking forward to the next steps in my career!
Internship Completion Certificate:
Proficient in Python | SCE'25 | Final year | Be a part of T&P cell | Campus Ambassador | C & C++ | Content creator | Graphics design
3 个月Thanks ????
Thanks for sharing ?
|| Student || ? || B.tech AI & ML || ? || ADCA || ? || C++ || ? || Python || ? || AI/ML Enthusiast || ? || DSA ||
9 个月Such an amazing talent, Keep growing Divyansh ?