0% found this document useful (0 votes)
2 views

Functions_List_Tuple_String

Uploaded by

bruhanth2008
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Functions_List_Tuple_String

Uploaded by

bruhanth2008
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Functions of Lists, Tuples, and Strings in Python

Functions of Lists, Tuples, and Strings

# Functions of Lists, Tuples, and Strings in Python

Below is a detailed explanation of common functions used with lists, tuples, and strings in Python.

Each function includes a description and examples.

---

## **List Functions**

### **1. append()**

- Adds an element to the end of the list.

```python

my_list = [1, 2, 3]

my_list.append(4)

print(my_list) # Output: [1, 2, 3, 4]

```

### **2. extend()**

- Extends the list by appending elements from another iterable (e.g., list, tuple).

```python

my_list = [1, 2, 3]
Functions of Lists, Tuples, and Strings in Python

my_list.extend([4, 5])

print(my_list) # Output: [1, 2, 3, 4, 5]

```

### **3. insert()**

- Inserts an element at a specified position.

```python

my_list = [1, 2, 4]

my_list.insert(2, 3)

print(my_list) # Output: [1, 2, 3, 4]

```

... (truncated for brevity; complete text used in actual PDF)

---

## **Tuple Functions**

### **1. count()**

- Returns the number of occurrences of a specified value.

```python

my_tuple = (1, 2, 2, 3)

print(my_tuple.count(2)) # Output: 2

```
Functions of Lists, Tuples, and Strings in Python

---

## **String Functions**

### **1. upper()**

- Converts all characters in the string to uppercase.

```python

my_string = "hello"

print(my_string.upper()) # Output: "HELLO"

```

... (continued for other functions)

You might also like