Python for Beginners, Assignments of Theory of Formal Languages for Automata

Python for Beginners 2026-2027, Home Assignment

Typology: Assignments

2025/2026

Available from 05/18/2026

daksh-meher
daksh-meher 🇮🇳

7 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python for Beginners
Que. 1: Explain List Data Type and it’s methods with suitable
example. (10 Marks)
What is a List?
In Python, a List is a built-in data type used to store multiple items in a
single variable. Lists are created using square brackets [].
Key Features:
Ordered: Items have a defined order that will not change.
Mutable: You can change, add, or remove items after the list is
created.
Allows Duplicates: Lists can have two items with the same value.
Common List Methods
1. append(): Adds an element at the end of the list.
2. insert(): Adds an element at a specific position.
3. remove(): Removes the first item with the specified value.
4. pop(): Removes the element at a specific position (or the last one if
not specified).
5. sort(): Sorts the list in ascending order.
Example Code:
# Creating a list
fruits = ["apple", "banana", "cherry"]
# 1. append() - adding mango
fruits.append("mango")
# 2. insert() - adding orange at index 1
fruits.insert(1, "orange")
# 3. remove() - removing apple
pf2

Partial preview of the text

Download Python for Beginners and more Assignments Theory of Formal Languages for Automata in PDF only on Docsity!

Python for Beginners

Que. 1: Explain List Data Type and it’s methods with suitable example. (10 Marks) What is a List? In Python, a List is a built-in data type used to store multiple items in a single variable. Lists are created using square brackets []. Key Features:Ordered: Items have a defined order that will not change.  Mutable: You can change, add, or remove items after the list is created.  Allows Duplicates: Lists can have two items with the same value. Common List Methods

  1. append(): Adds an element at the end of the list.
  2. insert(): Adds an element at a specific position.
  3. remove(): Removes the first item with the specified value.
  4. pop(): Removes the element at a specific position (or the last one if not specified).
  5. sort(): Sorts the list in ascending order. Example Code:

Creating a list

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

1. append() - adding mango

fruits.append("mango")

2. insert() - adding orange at index 1

fruits.insert(1, "orange")

3. remove() - removing apple

fruits.remove("apple") print(fruits)

Output: ['orange', 'banana', 'cherry', 'mango']

Que. 2: What is function in Python? Explain with suitable program code. (05 Marks) What is a Function? A Function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.  You define a function using the def keyword.  A function only runs when it is called. Program Code Example:

Defining a function

def greet_user(name): """This function greets the person passed in as a parameter""" print("Hello, " + name + ". Welcome to Python programming!")

Calling the function

greet_user("Amit") greet_user("Sita")

Output:

Hello, Amit. Welcome to Python programming!

Hello, Sita. Welcome to Python programming!