[go: up one dir, main page]

0% found this document useful (0 votes)
24 views49 pages

Model Inter Report

This document is an internship report submitted by Seenivasan A to partially fulfill the requirements for a Bachelor of Technology degree in Information Technology from Anna University. The report outlines the internship activities completed over 4 weeks at Bytes Learning focused on learning Python programming. Key topics covered in the curriculum included Python fundamentals, data manipulation, web development, and machine learning. Hands-on projects and coding exercises helped reinforce concepts. The internship improved the author's Python skills along with problem-solving, critical thinking, and soft skills like collaboration.

Uploaded by

vijay kumar
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)
24 views49 pages

Model Inter Report

This document is an internship report submitted by Seenivasan A to partially fulfill the requirements for a Bachelor of Technology degree in Information Technology from Anna University. The report outlines the internship activities completed over 4 weeks at Bytes Learning focused on learning Python programming. Key topics covered in the curriculum included Python fundamentals, data manipulation, web development, and machine learning. Hands-on projects and coding exercises helped reinforce concepts. The internship improved the author's Python skills along with problem-solving, critical thinking, and soft skills like collaboration.

Uploaded by

vijay kumar
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/ 49

PYTHON

INTERNSHIP REPORT

Submitted by

SEENIVASAN A 717822F249

in partial fulfilment for the award of the degree of

BACHELOR OF TECHNOLOGY
in
INFORMATION TECHNOLOGY

ANNA UNIVERSITY, CHENNAI

DEC - 2023
CERTIFICATE

This is to certify that the Internship report submitted by

SEENIVASAN A (717822F249) is work done by him and submitted during

2023 – 2024 academic year, in partial fulfillment of the requirements for the

award of the degreeof BACHELOR OF TECHNOLOGY in INFORMATION

TECHNOLOGY.

…………………… …………..……
Department Internship Coordinator Head of the Department

Certified that the candidate was examined in the viva-voce examination held on ……………..

…………………….. ……………………
Examiner 1 Examiner 2
INTERNSHIP CERTIFICATE
ACKNOWLEDGEMENT

We would like to show our gratitude to the management of Karpagam College

of Engineering Dr. R. VASANTHAKUMAR, B.E., (Hons), D.Sc., Chairman and

Managing Trustee, Karpagam Educational Institutions for providing us with all sorts

of supports in completion of this Internship.

We express our sincere and profound gratitude to our

Principal Dr. KUMAR CHINNAIYAN V, M.E., Ph.D., for his guidance and

sustained encouragement for the successful completion of this internship.

We feel immense pleasure in expressing our humble note of gratitude to our

Head of the Department Dr. N M SARAVANA KUMAR, M.E., Ph.D., for his

remarkable guidance and besides his positive approach he has offered incessant help

in all possible way from the beginning.

We would also like to recollect the courage and enthusiasm that was inculcated

in us by our internship coordinator Mr. P JEGATHESH M.TECH., Assistant

Professor, Department of Information Technology for valuable guidance and support

through the tenure of our internship.

We also extend our thanks to other faculty members, parents and friends

for providing their moral support in successfully completion of this Internship.


WEEKLY OVERVIEW OF INTERNSHIP ACTIVITIES
DATE DAY NAME OF THE TOPIC / MODULE COMLETED
31-07-2023 MONDAY INTRODUCTION TO PYTHON
WEEK 1

01-08-2023 TUESDAY KEYWORD


02-08-2023 WEDNESDAY KEYWORD
03-08-2023 THURSDAY IDENTIFIERS
04-08-2023 FRIDAY OPERATORS

DATE DAY NAME OF THE TOPIC / MODULE COMLETED


07-08-2023 MONDAY OPERATORS
WEEK 2

08-08-2023 TUESDAY OPERATORS


09-08-2023 WEDNESDAY DATATYPES
10-08-2023 THURSDAY DATATYPES
11-08-2023 FRIDAY LOOPS

DATE DAY NAME OF THE TOPIC / MODULE COMLETED


WEEK 3

14-08-2023 MONDAY LIST


16-08-2023 WEDNESDAY LIST
17-08-2023 THURSDAY TUPLE
18-08-2023 FRIDAY TUPLE

DATE DAY NAME OF THE TOPIC / MODULE COMLETED


22-08-2023 DICTIONARY
WEEK 4

TUESDAY
23-08-2023 WEDNESDAY DICTIONARY
24-08-2023 THURSDAY SET
25-08-2023 FRIDAY SET

DATE DAY NAME OF THE TOPIC / MODULE COMLETED


28-08-2023 FUNCTIONS
WEEK 5

MONDAY
29-08-2023 TUESDAY LAMBDA FUNCTION
30-08-2023 WEDNESDAY OBJECT ORIENTED PROGRAMMING
31-08-2023 THURSDAY OBJECT ORIENTED PROGRAMMING
TABLE OF CONTENTS
CHAPTER TITLE PAGE NO
NO
ABSTRACT i
LIST OF FIGURES ii
LIST OF TABLES iii
1 INTRODUCTION 1
1.1 PYTHON 1
1.2 HISTORY OF PYTHON 1
1.3 FEATURES OF PYTHON 1
2 KEYWORDS AND IDENTIFIERS 2
2.1 INTRODUCTION TO KEYWORDS 2
2.1.1 LIST OF KEYWORDS 2
2.2 IDENTIFIERS 7
2.2.1 RULES 8
2.2.2 EXAMPLES 8
3 OPERATORS 9
3.1 TYPES OF OPERATORS 9
3.2 ARITHEMATIC OPERATORS 9
3.3 COMPARISION OPERATOR 10
3.4 LOGICAL OPERATORS 11
3.5 BITWISE OPERATORS 12
3.6 ASSIGNMENT OPERATOR 13
3.7 IDENTITY OPERATOR 15
3.8 MEMBERSHIP OPERATOR 15
4 DATA TYPES 16
4.1 type() FUNCTION 17
4.2 NUMERIC DATA TYPES 17
4.3 SEQUENCE DATA TYPE 17
4.3.1 STRING DATA TYPE 18
4.3.2 LIST DATA TYPE 18
4.3.3 TUPLE 18
4.4 SET 18
4.5 DICTIONARY 19
4.6 BOOLEAN 19
5 LOOPS 20
5.1 INTRODUCTION 20
5.2 WHILE LOOP 20
5.2.1 USING ELSE STATEMENT 20
5.3 FOR LOOP 21
5.3.1 FOR USING ELSE 21
5.3.2 NESTED LOOPS 22
5.4 LOOP CONTROL STATEMENTS 22
5.4.1 CONTINUE STATEMENT 22
5.4.2 BREAK STATEMENT 22
5.4.3 PASS STATEMENT 22
6 LISTS 23
6.1 INTRODUCTION 23
6.2 FEATURES OF LIST 23
6.3 CREATING A LIST 23
6.4 LIST FUNCTIONS 24
6.5 ACCESSING ITEMS 25
6.6 MODIFYING LIST 26
7 TUPLES 28
7.1 INTRODUCTION 28
7.2 CREATING TUPLES 28
7.3 ROUND BRACKETS () 28
7.4 TUPLE WITH ONE ITEM 29
7.5 TUPLE CONSTRUCTOR 29
7.6 FEATURES OF TUPLES 30
7.7 CHARACTERISTICS OF TUPLES 30
7.8 TUPLE OPERATIONS 31
7.8.1 CONCATENATION 31
7.8.2 NESTING 32
7.8.3 REPETITION 32
7.8.4 SLICING 33
7.8.5 DELETING A TUPLE 33
7.8.6 FINDING THE LENGTH 34
7.8.7 MULTIPLE DATA TYPES 35
7.8.8 LIST TO A TUPLE 35
7.8.9 TUPLES IN A LOOP 36
8 CONCLUSION 37
ABSTRACT

This report encapsulates the enriching experience gained during the Bytes
Learning internship, focused on Python programming. The internship aimed to
empower participants with a comprehensive understanding of Python and its
applications in the realm of education technology. The report outlines the key
components of the internship, including the curriculum, hands-on projects, and
collaborative learning environment.

The curriculum delved into fundamental Python concepts, progressing


towards advanced topics such as data manipulation, web development, and machine
learning. Practical sessions, coding exercises, and real-world projects were integral
in reinforcing theoretical knowledge. The internship also fostered a culture of
collaboration, encouraging participants to engage in peer-to-peer learning and
contribute to group projects.

The report highlights the impact of the internship on skill development,


including proficiency in Python programming, problem-solving, and critical
thinking. Insights gained from real-world projects, such as developing educational
tools and automating processes, showcase the practical applicability of Python in
educational technology.

The Bytes Learning internship on Python programming not only equipped


participants with technical skills but also nurtured soft skills such as teamwork,
communication, and adaptability. The report concludes with reflections on the
overall impact of the internship, emphasizing the importance of continuous learning
and practical application of Python programming in the dynamic field of educational
technology.

i
LIST OF FIGURES

FIGURE NO TITLE PAGE NO.

2.1 OUTPUT FOR KEYWORD PROGRAM 7

4.1 TYPES OF DATA TYPES 16

8.1 NESTED DICTIONARIES 38

10.1 FUNCTION DECLARATION 45

ii
LIST OF TABLES

TABLE NO TABLE NAME PAGE NO

2.1 Keywords 2

2.2 Examples of Identifiers 8

3.1 Arithmetic Operator 10

3.2 Comparison Operator 11

3.3 Logical Operators 12

3.4 Bitwise Operators 12

3.5 Assignment Operator 13

6.1 List functions 24

8.1 Dictionary methods 39

iii
CHAPTER 1
INTRODUCTION

1.1 PYTHON
Python is a widely used high-level, general-purpose, interpreted, dynamic
programming language.
Its design philosophy emphasizes code readability, and its syntax allows
programmers to express concepts in fewer lines of code than would be possible in
languages such as C++ or Java.
The language provides constructs intended to enable clear programs on both a small
and large scale.

1.2 HISTORY OF PYTHON


Python was developed by Guido van Rossum in the late eighties and early
nineties at the National Research Institute for Mathematics and Computer Science
in the Netherlands.
Python is derived from many other languages, including ABC, Modula-3, C, C++,
Algol-68,SmallTalk, and Unix shell and other scripting languages.

1.3 FEATURES OF PYTHON


 It supports functional and structured programming methods as well as OOP.
 It can be used as a scripting language or can be compiled to byte-code for
building large applications.
 It provides very high-level dynamic data types and supports dynamic type
checking.
 IT supports automatic garbage collection.

1
CHAPTER 2

KEYWORDS AND IDENTIFIERS

2.1 INTRODUCTION TO KEYWORDS


Keywords in Python are several reserved words that you cannot use as a name
of your function, class, or variable. All these keywords have special meaning in the
language and thus each of them is used for a special purpose. Keywords define the
syntax as well as the structure of Python. There are 33 keywords in Python 3.7 and
there are 35 keywords in Python 3.11. Keywords in Python are case-sensitive. So,
all the keywords should be written in the way they are.

2.1.1 LIST OF KEYWORDS

Keyword Description Keyword Description Keyword Description


Represents
an
It is a It is a non-
expression
and Logical False nonlocal local
that will
Operator variable
result in not
being true.
It is used to It is used It is a
as create an finally with not Logical
alias name exceptions Operator
It is a
It is used for It is used to
assert for or Logical
debugging create Loop
Operator

2
pass is used
when the
To import
Break out a user doesn’t
break from specific parts pass
Loop want any
of a module
code to
execute

It is used to raise is used


It is used to declare a to raise
class global raise
define a class global exceptions or
variable errors.

Skip the next To create a return is


continue iteration of a if Conditional return used to end
loop Statement the execution

Represents
It is used to It is used to an
def define the import import a True expression
Function module that will
result in true.

It is used to
It is used to Try is used
test if two
del delete an is try to handle
variables are
object errors
equal
To check if a While Loop
Conditional
value is is used to
statements,
elif in present in a while execute a
same as else- Tuple, List, block of
if etc. statements
with
Used to
It is used in a statement is
create an
else conditional lambda with used in
anonymous
statement exception
function
handling

3
yield
try-except is keyword is
used to It represents used to
except None yield
handle these a null value create a
errors generator
function

Table 2.1 Keywords

EXAMPLE
Code:
# Logical Constants
print(True) # True
print(False) # False
print(None) # None

# Boolean Operators
result_and = True and False
result_or = True or False
result_not = not True

print(result_and) # False
print(result_or) # True
print(result_not) # False

# Conditional Statements
if True:
print("This block will be executed.")

# Looping

4
for i in range(3):
print(i)

# Function Definition
def my_function(parameter):
print("Function called with:", parameter)

my_function("Hello")

# Exception Handling
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero.")

# Class Definition
class MyClass:
def _init_(self):
print("An instance of MyClass is created.")

obj = MyClass()

# Importing Modules
import math
print(math.sqrt(25)) # 5.0

# Context Managers (with statement)


5
with open("example.txt", "w") as file:
file.write("Hello, this is an example.")

# Lambda Functions
square = lambda x: x ** 2
print(square(4)) # 16

# Yield (Generator function)


def my_generator():
yield 1
yield 2

gen = my_generator()
print(next(gen)) # 1
print(next(gen)) # 2

6
Output:

Figure 2.1 Output for keywords program

2.2 IDENTIFIERS

A variable name is known as an identifier in Python. However, when you are


naming a variable, you have to follow a set of rules. For example, here the variable
is of integer type. This holds the value of 20. The name of the variable “number” is
called an identifier.

number = 20

Some points to remember while naming an identifier in Python:

1. While declaring a variable, you need to make sure that it starts with a letter or
an underscore. For example _number, Number_, Str, etc are all valid names
for variables.

7
2. You cannot start the name of your variable with a number. 7Str_ is not a valid
variable.
3. You cannot include special characters in the variables such as $, &, %, etc.
You can use only alphanumeric characters.
4. Variable names in Python are always case-sensitive. This is why NUMBER
and number are two different names.

2.2.1 RULES

 Identifier names are unique.


 Cannot use a keyword as identifiers.
 Identifier has to begin with a letter or underscore (_).
 It should not contain white space.
 Special characters are not allowed.
 Identifiers can consist of only letters, digits, or underscore.
 Only 31 characters are significant.
 They are case sensitive.

2.2.2 EXAMPLES
Valid Identifiers Invalid Identifiers
score @core
return_value return
highest_score highest score
name1 1name
convet_to_string convet to_string

Table 2.2 Examples of Identifiers

8
CHAPTER 3

OPERATORS

In Python programming, Operators in general are used to perform operations


on values and variables. These are standard symbols used for the purpose of logical
and arithmetic operations. In this article, we will look into different types of Python
operators.

OPERATORS: These are the special symbols. Eg- + , * , /, etc.

OPERAND: It is the value on which the operator is applied.

3.1 TYPES OF OPERATORS


There are six types of Operators in Python.
 Arithmetic Operators
 Comparison Operators
 Logical Operators
 Bitwise Operators
 Assignment Operators
 Identity Operators and Membership Operators

3.2 ARITHEMATIC OPERATORS


Python Arithmetic operators are used to perform basic mathematical
operations like addition, subtraction, multiplication, and division. In Python 3.x the
result of division is a floating-point while in Python 2.x division of 2 integers was
an integer. To obtain an integer result in Python 3.x floored (// integer) is used.

9
Operator Description Syntax
Addition: adds two
+ x+y
Operands
Subtraction: subtracts two
– x–y
Operands
Multiplication: multiplies
* x*y
two operands
Division (float): divides
/ the first operand by the x/y
Second
Division (floor): divides
// the first operand by the x // y
Second
Modulus: returns the
remainder when the first
% x%y
operand is divided by the
second
Power: Returns first raised
** x ** y
to power second
Table 3.1 Arithmetic Operators

3.3 COMPARISION OPERATOR


In Python Comparison of Relational operators compares the values. It either
returns True or False according to the condition.

10
Operator Description Syntax
Greater than: True if the left
> operand is greater than the x>y
right
Less than: True if the left
< x<y
operand is less than the right
Equal to: True if both
== x == y
operands are equal
Not equal to – True if
!= x != y
operands are not equal
Greater than or equal to True
>= if the left operand is greater x >= y
than or equal to the right
Less than or equal to True if
<= the left operand is less than or x <= y
equal to the right

Table 3.2 Comparison Operator

3.4 LOGICAL OPERATORS


Python Logical operators perform Logical AND, Logical OR, and Logical
NOT operations. It is used to combine conditional statements. In Python, Logical
operators are used on conditional statements (either True or False). They perform
Logical AND, Logical OR and Logical NOT operations.

11
Operator Description Syntax

Logical AND: True if


and x and y
both the operands are true

Logical OR: True if either


or x or y
of the operands is true

Logical NOT: True if the


not not x
operand is false
Table 3.3 Logical Operators

3.5 BITWISE OPERATORS


In Python, bitwise operators are used to perform bitwise calculations on
integers. The integers are first converted into binary and then operations are
performed on each bit or corresponding pair of bits, hence the name bitwise
operators.
The result is then returned in decimal format.
Operator Description Syntax
& Bitwise AND x&y
| Bitwise OR x|y
~ Bitwise NOT ~x
^ Bitwise XOR x^y
>> Bitwise right shift x>>
<< Bitwise left shift x<<
Table 3.4 Bitwise Operators

12
3.6 ASSIGNMENT OPERATOR
Python Assignment operators are used to assign values to the variables.
Operator Description Syntax
Assign the value of the
right side of the
= x=y+z
expression to the left side
operand
Add right-side operand
with left-side operandand
+= a+=b a=a+b
then assign to left
operand
Subtract right operand
from left operand and
-= a-=b a=a-b
then assign to left
operand
Divide AND: Divide left
operand with right
/= a/=b a=a/b
operand and then assign
to left operand
Modulus AND: Takes
modulus using left and
%= a%=b a=a%b
right operands and assign
the result to left operand

13
Divide(floor) AND:
Divide left operand with
//= right operand and then a//=b a=a//b
assign the value(floor) to
left operand
Exponent AND:
Calculate exponent(raise
**= power) value using a**=b a=a**b
operands and assign value
to left operand

Performs Bitwise ANDon


&= operands and assign value a&=b a=a&b
to left operand

Performs Bitwise OR on
|= operands and assign value a|=b a=a|b
to left operand
Performs Bitwise xOR on
^= operands and assign value a^=b a=a^b
to left operand
Performs Bitwise right
shift on operands and
>>= a>>=b a=a>>b
assign value to left
operand

14
Performs Bitwise left
shift on operands and
<<= a <<= b a= a << b
assign value to left
operand
Table 3.5 Assignment Operator

3.7 IDENTITY OPERATOR


is True if the operands are identical
is not True if the operands are not identical

3.8 MEMBERSHIP OPERATOR


in True if value is found in the sequence
not in True if value is not found in the sequence

15
CHAPTER 4

DATA TYPES

Data types are the classification or categorization of data items. It represents


the kind of value that tells what operations can be performed on a particular data.
Since everything is an object in Python programming, data types are classes and
variables are instances (objects) of these classes.
The following are the standard or built-in data types in Python:
 Numeric
 Sequence Type
 Boolean
 Set
 Dictionary

Figure 4.1 Types of Data Types

16
4.1 type() FUNCTION
To define the values of various data types and check their data types we use
the type() function.

4.2 NUMERIC DATA TYPES IN PYTHON


The numeric data type in Python represents the data that has a numeric value. A
numeric value can be an integer, a floating number, or even a complex number.
These values are defined as Python int, Python float, and Python complex classes in
Python.
 Integers – This value is represented by int class. It contains positive or
negative whole numbers (without fractions or decimals). In Python, there is
no limit to how long an integer value can be.
 Float – This value is represented by the float class. It is a real number with a
floating-point representation. It is specified by a decimal point. Optionally,
the character e or E followed by a positive or negative integer may be
appended to specify scientific notation.
 Complex Numbers – A complex number is represented by a complex class. It
is specified as (real part) + (imaginary part)j. For example – 2+3j

4.3 SEQUENCE DATA TYPE IN PYTHON


The sequence Data Type in Python is the ordered collection of similar or different
data types. Sequences allow storing of multiple values in an organized and efficient
fashion. There are several sequence types in Python –
 String
 List

17
 Tuple
4.3.1 STRING DATA TYPE
Strings in Python are arrays of bytes representing Unicode characters. A string
is a collection of one or more characters put in a single quote, double-quote, or triple-
quote. In Python there is no character data type, a character is a string of length one.
It is represented by str class.
Strings in Python can be created using single quotes, double quotes, or even triple
quotes.

4.3.2 LIST DATA TYPE


Lists are just like arrays, declared in other languages which is an ordered
collection of data. It is very flexible as the items in a list do not need to be of the
same type.
Lists in Python can be created by just placing the sequence inside the square

4.3.3 TUPLE

Just like a list, a tuple is also an ordered collection of Python objects. The only
difference between a tuple and a list is that tuples are immutable i.e. tuples cannot
be modified after it is created. It is represented by a tuple class.

4.4 SET

In Python, a Set is an unordered collection of data types that is iterable,


mutable, and has no duplicate elements. The order of elements in a set is undefined
though it may consist of various elements.

18
4.5 DICTIONARY

A dictionary in Python is an unordered collection of data values, used to


store data values like a map, unlike other Data Types that hold only a single value
as an element, a Dictionary holds a key: value pair. Key-value is provided in the
dictionary to make it more optimized. Each key-value pair in a Dictionary is
separated by a colon : , whereas each key is separated by a ‘comma’.

4.6 BOOLEAN

Data type with one of the two built-in values, True or False. Boolean objects
that are equal to True are truthy (true), and those equal to False are falsy (false).
However non-Boolean objects can be evaluated in a Boolean context as well and
determined to be true or false. It is denoted by the class bool.
Note – True and False with capital ‘T’ and ‘F’ are valid booleans otherwise python
will throw an error.

19
CHAPTER 5

LOOPS

5.1 INTRODUCTION

programming language provides two types of loops – For loop and While
loop to handle looping requirements. Python provides three ways for executing the
loops.
While all the ways provide similar basic functionality, they differ in their syntax and
condition-checking time.

5.2 WHILE LOOP


In Python, a while loop is used to execute a block of statements repeatedly
until a given condition is satisfied. When the condition becomes false, the line
immediately after the loop in the program is executed.
SYNTAX:
while expression:
statements(s)
All the statements indented by the same number of character spaces after a
programming construct are considered to be part of a single block of code. Python
uses indentation as its method of grouping statements.

5.2.1 USING ELSE STATEMENT WITH WHILE LOOP


The else clause is only executed when your while condition becomes false.
If you break out of the loop, or if an exception is raised, it won’t be executed.

20
SYNTAX:
while condition:
# execute these statements
else:
# execute these statements

5.3 FOR LOOP


For loops are used for sequential traversal. For example: traversinga
list or string or array etc. In Python, there is “for in” loop which is similar to
foreach loop in other languages. Let us learn how to use for loop in Python for
sequential traversals with examples.
SYNTAX:
for iterator_var in sequence:
statements(s)

It can be used to iterate over a range and iterators.

5.3.1 USING ELSE STATEMENT WITH FOR LOOP


We can also combine else statement with for loop like in while loop. But as
there is no condition in for loop based on which the execution will terminate so the
else block will be executed immediately after for block finishes execution.
In this code, the ‘for' loop iterates over a list and prints each element, just like in the
previous example. However, after the loop is finished, the “else” block is executed.
So, in this case, it will print “Inside Else Block” once the loop completes.

21
5.3.2 NESTED LOOPS
Python programming language allows to use one loop inside another loop
which is called nested loop. Following section shows few examples to illustrate the
concept.
SYNTAX:
for iterator_var in sequence:
for iterator_var in sequence:
statements(s)
statements(s)

5.4 LOOP CONTROL STATEMENTS


Loop control statements change execution from their normal sequence. When
execution leaves a scope, all automatic objects that were created in that scopeare
destroyed. Python supports the following control statements.

5.4.1 CONTINUE STATEMENT


The continue statement in Python returns the control to the beginning of the
loop.

5.4.2 BREAK STATEMENT


The break statement in Python brings control out of the loop.

5.4.3 PASS STATEMENT


We use pass statement in Python to write empty loops. Pass is also used for
empty control statements, functions and classes.

22
CHAPTER 6

LISTS

6.1 INTRODUCTION

Lists are used to store multiple items in a single variable. Lists are one of 4
built-in data types in Python used to store collections of data, the other 3 are Tuple,
Set, and Dictionary, all with different qualities and usage. It is one of the collections
in python.

6.2 FEATURES OF LIST

 Ordered
 Changeable
 Allow Duplicates
 Mutable

6.3 CREATING A LIST

A list can be created using Square brackets which is used to differentiate it


with other collection types in python.

Eg:

mylist = ["apple", "banana", "cherry"]

An empty list can also be created with the list function.

23
Eg:

listB = list()

6.4 LIST FUNCTIONS

There are various types of functions that can be used with lists. They are

Method Description
append() Adds an element at the end of the list.

clear() Removes all the elements from the list.

copy() Returns a copy of the list.

count() Returns the number of elements with the specified value.

extend() Add the elements of a list (or any iterable), to the end of the current
list.

index() Returns the index of the first element with the specified value.

insert() Adds an element at the specified position.

pop() Removes the element at the specified position.

remove() Removes the first item with the specified value.

reverse() Reverses the order of the list.

sort() Sorts the list.

Table 6.1 List functions

24
6.5 ACCESSING ITEMS

List items are indexed and you can access them by referring to the index number.
There are two ways to access using index,

 Positive indexing
 Negative indexing

Positive indexing:

The first item has index 0.

Eg:

thislist = ["apple", "banana", "cherry"]


print(thislist[1])

Negative indexing:

Negative indexing means start from the end. -1 refers to the last item, -2 refers
to the second last item etc.

Eg:

thislist = ["apple", "banana", "cherry"]


print(thislist[-1])

Range of Indexes:

We can specify a range of indexes by specifying where to start and where to


end the range. When specifying a range, the return value will be a new list with the
specified items.

25
Eg:

thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]


print(thislist[2:5])

6.6 MODIFYING LIST

Append items:

To add an item to the end of the list, use the append() method:

Eg:

thislist = ["apple", "banana", "cherry"]


thislist.append("orange")
print(thislist)

Change Item Value:

To change the value of a specific item, refer to the index number:

Eg:

thislist = ["apple", "banana", "cherry"]


thislist[1] = "blackcurrant"
print(thislist)

26
Change a Range of Item Values:

To change the value of items within a specific range, define a list with the new
values, and refer to the range of index numbers where you want to insert the new
values:

Eg:

thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"]

thislist[1:3] = ["blackcurrant", "watermelon"]

print(thislist)

27
CHAPTER 7

TUPLES

7.1 INTRODUCTION
Python Tuple is a collection of objects separated by commas. In some ways,
a tuple is similar to a Python list in terms of indexing, nested objects, and repetition
but the main difference between both is Python tuple is immutable, unlike the Python
list which is mutable.

7.2 CREATING TUPLES


There are various ways by which you can create a tuple in Python. They are as
follows:
 Using round brackets
 With one item
 Tuple Constructor

7.3 CREATE TUPLES USING ROUND BRACKETS ()

To create a tuple we will use () operators.

Eg:

var = ("Geeks", "for", "Geeks")

print(var)

28
Output:

('Geeks', 'for', 'Geeks')

7.4 CREATE A TUPLE WITH ONE ITEM

Python 3.11 provides us with another way to create a Tuple.

Eg:

values : tuple[int | str, ...] = (1,2,4,"Geek")

print(values)

Output:

(1, 2, 4, 'Geek')

7.5 TUPLE CONSTRUCTOR

To create a tuple with a Tuple constructor, we will pass the elements as its
parameters.

Eg:

tuple_constructor = tuple(("dsa", "developement", "deep learning"))

print(tuple_constructor)

Output :

('dsa', 'developement', 'deep learning')

29
7.6 FEATURES OF TUPLES OVER SET

Tuples in Python are similar to Python lists but not entirely.

Tuples are

 Immutable
 Ordered
 Allow Duplicates

7.7 CHARACTERISTICS OF TUPLES

 We can find items in a tuple since finding any item does not make changes in
the tuple.
 One cannot add items to a tuple once it is created.
 Tuples cannot be appended or extended.
 We cannot remove items from a tuple once it is created.

Eg:

mytuple = (1, 2, 3, 4, 5)

print(mytuple[1])

print(mytuple[4])

mytuple = (1, 2, 3, 4, 2, 3)

print(mytuple)

mytuple[1] = 100

print(mytuple)

30
Output:

(1, 2, 3, 4, 2, 3)

Traceback (most recent call last):

File "e0eaddff843a8695575daec34506f126.py", line 11, in

tuple1[1] = 100

TypeError: 'tuple' object does not support item assignment

7.8 DIFFERENT OPERATIONS RELATED TO TUPLES

 Concatenation
 Nesting
 Repetition
 Slicing
 Deleting
 Finding the length
 Multiple Data Types with tuples
 Conversion of lists to tuples
 Tuples in a Loop

7.8.1 CONCATENATION

To Concatenation of Python Tuples, we will use plus operators(+).

31
Eg:

tuple1 = (0, 1, 2, 3)

tuple2 = ('python', 'geek')

print(tuple1 + tuple2)

Output:

(0, 1, 2, 3, 'python', 'geek')

7.8.2 NESTING

A nested tuple in Python means a tuple inside another tuple.

Eg:

tuple1 = (0, 1, 2, 3)

tuple2 = ('python', 'geek')

tuple3 = (tuple1, tuple2)

print(tuple3)

Output :

((0, 1, 2, 3), ('python', 'geek'))

7.8.3 REPETITION

We can create a tuple of multiple same elements from a single element in that
tuple.

32
Program:

tuple3 = ('python',)*3

print(tuple3)

Output:

('python', 'python', 'python')

7.8.4 SLICING

Slicing a Python tuple means dividing a tuple into small tuples using the
indexing method.

Program:

tuple1 = (0 ,1, 2, 3)

print(tuple1[1:])

print(tuple1[::-1])

print(tuple1[2:4])

Output:

(1, 2, 3)

(3, 2, 1, 0)

(2, 3)

33
7.8.5 DELETING A TUPLE

Program:

tuple3 = ( 0, 1)

del tuple3

print(tuple3)

Output:

Traceback (most recent call last):

File "d92694727db1dc9118a5250bf04dafbd.py", line 6, in <module>

print(tuple3)

NameError: name 'tuple3' is not defined

Note: Remove individual tuple elements is not possible, but we can delete the whole
Tuple using Del keyword.

7.8.6 FINDING THE LENGTH

To find the length of a tuple, we can use Python’s len() function and pass the
tuple as the parameter.

Program:

tuple2 = ('python', 'geek')

34
print(len(tuple2))

Output:

7.8.7 MULTIPLE DATA TYPES WITH TUPLE

Tuples in Python are heterogeneous in nature. This means tuples support


elements with multiple datatypes.

Program:

tuple_obj = ("immutable",True,23)

print(tuple_obj)

Output :

('immutable', True, 23)

7.8.8 CONVERTING A LIST TO A TUPLE

We can convert a list in Python to a tuple by using the tuple() constructor and
passing the list as its parameters.

Program:

list1 = [0, 1, 2]

print(tuple(list1))

print(tuple('python'))

35
Output:

(0, 1, 2)

('p', 'y', 't', 'h', 'o', 'n')

Note: Tuples take a single parameter which may be a list, string, set, or even a
dictionary(only keys are taken as elements), and converts them to a tuple.

7.8.9 TUPLES IN A LOOP

We can also create a tuple with a single element in it using loops.

Program:

tup = ('geek',)

n=5

for i in range(int(n)):

tup = (tup,)

print(tup)

Output:

(('geek',),)

((('geek',),),)

(((('geek',),),),)

((((('geek',),),),)

36
CHAPTER 8

CONCLUSION

The Python learning experience at Bytes Learning has been both enriching
and impactful, providing a comprehensive exploration of the language's versatility
and applications. Throughout the learning journey, a diverse range of topics has been
covered, spanning from fundamental concepts to advanced features and best
practices in Python programming.

One of the key strengths of Bytes Learning's Python program lies in its well-
structured curriculum. The program effectively navigated through the basics of
Python syntax, data structures, and control flow, gradually progressing towards more
advanced topics such as object-oriented programming, file handling, and working
with external libraries. This structured approach has facilitated a holistic
understanding of Python, empowering learners to tackle complex programming
challenges.

The mentorship and support provided by the Bytes Learning instructors have
been commendable. The guidance offered by experienced professionals has been
instrumental in addressing queries, clarifying concepts, and fostering a collaborative
learning environment. Regular feedback sessions have further enhanced the learning
experience, ensuring continuous improvement and refinement of coding skills.

As I conclude my internship with Bytes Learning, I carry forward a wealth of


knowledge, skills, and experiences that will undoubtedly shape my future endeavors.
I express my gratitude to the entire Bytes Learning team for this incredible
opportunity and look forward to applying the lessons learned during this internship
to contribute meaningfully to the field of programming.

37
REFERENCES

TEXTBOOKS REFERENCES
1. "Python Crash Course" by Eric Matthes
2. "The python programming" by John M Zelle

WEB REFERENCES
1. Official Python Documentation: -
[PythonDocumentation](https://docs.python.org/3/)
2. Tutorials and Guides: - [Real Python](https://realpython.com/) -
[Geeks for Geeks Python Programming Language]
(https://www.geeksforgeeks.org/python-programming-language/)
3. Community Resources: - [Stack
Overflow](https://stackoverflow.com/questions/tagged/python) -
[Python Reddit Community](https://www.reddit.com/r/Python/)
4. Online Learning Platforms: - [Code academy Python
Course](https://www.codecademy.com/learn/learnpython3) -
[Coursera Python for Everybody Specialization]
(https://www.coursera.org/specializations/python)

38

You might also like