Server Side Programming Articles

Page 574 of 2109

Built-in Tuple Functions in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 10K+ Views

Python provides several built-in functions to work with tuples. These functions help you perform common operations like finding length, maximum/minimum values, and converting sequences to tuples. len() Function The len() function returns the total number of elements in a tuple ? numbers = (1, 2, 3, 4, 5) fruits = ('apple', 'banana', 'orange') empty_tuple = () print("Length of numbers:", len(numbers)) print("Length of fruits:", len(fruits)) print("Length of empty tuple:", len(empty_tuple)) Length of numbers: 5 Length of fruits: 3 Length of empty tuple: 0 max() Function The max() function returns the ...

Read More

No Enclosing Delimiters in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 347 Views

In Python, when you write multiple objects separated by commas without any enclosing delimiters (like brackets [] for lists or parentheses () for tuples), Python automatically treats them as tuples. This behavior is called implicit tuple creation. Basic Tuple Creation Without Delimiters Here's how Python interprets comma-separated values without delimiters ? # Multiple values without delimiters create a tuple data = 'abc', -4.24e93, 18+6.6j, 'xyz' print(data) print(type(data)) ('abc', -4.24e+93, (18+6.6j), 'xyz') Tuple Unpacking This implicit tuple creation is commonly used with tuple unpacking ? # Tuple unpacking ...

Read More

Basic Tuples Operations in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 562 Views

Tuples respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new tuple, not a string. In fact, tuples respond to all of the general sequence operations we used on strings in the prior chapter − Basic Tuple Operations Python Expression Results Description ...

Read More

Delete Tuple Elements in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 8K+ Views

Tuples are immutable in Python, meaning you cannot delete individual elements from an existing tuple. However, you can create a new tuple with unwanted elements removed, or delete the entire tuple variable using the del statement. Why You Cannot Delete Individual Elements Tuples are immutable data structures, so operations like del tuple[index] will raise a TypeError ? subjects = ('physics', 'chemistry', 'math', 'biology') # This will raise an error try: del subjects[1] except TypeError as e: print(f"Error: {e}") Error: 'tuple' object doesn't support item ...

Read More

Built-in List Functions & Methods in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 22K+ Views

Python provides numerous built-in functions and methods to work with lists efficiently. These functions help perform common operations like finding length, maximum/minimum values, and converting sequences to lists. Built-in List Functions Python includes the following list functions ? Sr.No Function with Description ...

Read More

Basic List Operations in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 2K+ Views

Lists are sequence objects in Python that support the same fundamental operations as strings. They respond to the + and * operators for concatenation and repetition, except the result is a new list rather than a string. Lists support all general sequence operations, making them versatile for data manipulation and processing tasks. Length Operation Use len() to get the number of elements in a list − numbers = [1, 2, 3] print("Length of list:", len(numbers)) Length of list: 3 Concatenation with + Operator Combine two lists using the + ...

Read More

Built-in String Methods in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 5K+ Views

Python provides a rich set of built-in string methods for manipulating and working with text data. These methods cover everything from case conversion and formatting to searching and validation. Case Conversion Methods Methods for changing the case of characters in strings ? text = "hello WORLD" print("Original:", text) print("capitalize():", text.capitalize()) print("upper():", text.upper()) print("lower():", text.lower()) print("title():", text.title()) print("swapcase():", text.swapcase()) Original: hello WORLD capitalize(): Hello world upper(): HELLO WORLD lower(): hello world title(): Hello World swapcase(): HELLO world String Validation Methods Methods that return True or False based on string content ...

Read More

Unicode String in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 3K+ Views

In Python, Unicode strings allow you to work with characters from various languages and special symbols. While Python 2 required the u prefix for Unicode strings, Python 3 treats all strings as Unicode by default. Unicode in Python 3 In Python 3, all strings are Unicode by default, so no special prefix is needed ? # All strings are Unicode in Python 3 text = 'Hello, world! 你好 مرحبا' print(text) print(type(text)) Hello, world! 你好 مرحبا Working with Unicode Characters You can use Unicode escape sequences to represent special characters ...

Read More

Triple Quotes in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 7K+ Views

Python's triple quotes allow strings to span multiple lines, including verbatim newlines, tabs, and any other special characters. This feature is particularly useful for multi-line strings, docstrings, and preserving text formatting. The syntax for triple quotes consists of three consecutive single (''') or double (""") quotes. Syntax # Using triple double quotes text = """Multi-line string content""" # Using triple single quotes text = '''Multi-line string content''' Basic Multi-line String Example Triple quotes preserve all whitespace and special characters within the string ? para_str = """This is a ...

Read More

String Special Operators in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 3K+ Views

Python provides several special operators for working with strings. These operators allow you to concatenate, repeat, slice, and format strings efficiently. Let's explore each operator with practical examples using string variables a = 'Hello' and b = 'Python'. String Concatenation (+) The + operator joins two or more strings together ? a = 'Hello' b = 'Python' result = a + b print(result) print(a + ' ' + b) HelloPython Hello Python String Repetition (*) The * operator creates multiple copies of a string ? a = 'Hello' ...

Read More
Showing 5731–5740 of 21,090 articles
« Prev 1 572 573 574 575 576 2109 Next »
Advertisements