Found 10784 Articles for Python

Why do you think tuple is an immutable in Python?

Pranav Indukuri
Updated on 05-Sep-2022 09:16:38

4K+ Views

In this article, we will discuss why tuples in python are immutable. Before moving on, we will understand tuples in detail. Tuple Tuples are a data type that belongs to the sequence data type category. They're similar to lists in Python, but they have the property of being immutable. We can't change the elements of a tuple, but we can execute a variety of actions on them such as count, index, type, etc. Tuples are created in Python by placing a sequence of values separated by a 'comma', with or without the use of parenthesis for data grouping. Tuples can ... Read More

What is the difference between a python tuple and a dictionary?

Pranav Indukuri
Updated on 03-Nov-2023 00:45:49

14K+ Views

In this article, we will discuss the difference between a python tuple and dictionary. Tuple Tuples are a data type that belongs to the sequence data type category. They're similar to lists in Python, but they have the property of being immutable. We can't change the elements of a tuple, but we can execute a variety of actions on them such as count, index, type, etc. Tuples are created in Python by placing a sequence of values separated by a 'comma', with or without the use of parenthesis for data grouping. Tuples can have any number of elements and any ... Read More

What is the difference between a python list and an array?

Pranav Indukuri
Updated on 03-Nov-2023 00:50:13

3K+ Views

In Python, both array and the list are used to store the data as a data structure. In this article, we discuss the difference between a list and an array. List Lists are one of the four most commonly used data structures provided by Python. A list is a data structure in python that is mutable and has an ordered sequence of elements. Lists also support negative indexing. Following is a list of integer values − lis= [1, 2, 3, 4, 5] print(lis) Output If you execute the above snippet, produces the following output − [1, 2, 3, 4, ... Read More

How to declare a variable in Python without assigning a value to it?

Pranav Indukuri
Updated on 03-Nov-2023 02:00:45

7K+ Views

Python variable is a symbolic name for an object that serves as a reference or pointer. You can refer to an object by its name once it has been assigned to a variable. The data, on the other hand, is still contained within the object. For example, a is assigned the value 100. ‘a’ is a variable. a = 100 This assignment creates an integer object with the value 100 and assigns the variable a to point to that object. In the above example, we have assigned a value(100) to the variable, but in this article, we will see ... Read More

What is the difference between working of append and + operator in a list in Python?

Pranav Indukuri
Updated on 03-Nov-2023 02:09:10

3K+ Views

In this article, we will look at what is the difference between the append and the plus operator in a list. The append() method is used to add elements to the list by utilizing a mutator() method. The '+' operator is used to create a new list with the capacity for one more element. Behaviour of + operator while working with a list Python accesses each element of the first list by using the '+' operator. When the '+' symbol is used, a new list with the capacity for one more element is produced. The old list's elements ... Read More

What are the differences between list, sequence and slice data types in Python?

Rajendra Dharmkar
Updated on 08-May-2023 11:52:34

1K+ Views

We will learn about the differences between list, sequence, and slice data types in Python in this article. Lists − In Python, a list is a type of data that can hold multiple values in a single variable. You can think of it like a shopping list that contains multiple items. For example, you could have a list of numbers like [1, 2, 3, 4, 5] or a list of names like ["John", "Jane", "Bob", "Sue"]. Number_List = [1, 2, 3, 4, 5] Name_List = ["John", "Jane", "Bob", "Sue"] Sequences − In Python, a sequence is a type of data ... Read More

What is a sequence data type in Python?

Pranav Indukuri
Updated on 03-Nov-2023 02:20:57

12K+ Views

Sequence Data Types are used to store data in containers in the Python computer language. The different types of containers used to store the data are List, Tuple, and String. Lists are mutable and can hold data of any type, whereas Strings are immutable and can only store data of the str type. Tuples are immutable data types that can store any sort of value. List The sequential data-type class includes the list data type. The list is the sole mutable data type in the sequential category. It can store any data type's values or components. Many procedures in the ... Read More

How to index and slice lists in Python?

Pranav Indukuri
Updated on 03-Nov-2023 02:25:45

4K+ Views

Lists are one of the four most commonly used data structures provided by Python. A list is a data structure in python that is mutable and has an ordered sequence of elements. Following is a list of integer values. lis= [1, 2, 3, 4, 5] print(lis) If you execute the above snippet, produces the following output. [1, 2, 3, 4, 5] In this article, we will discuss how to index and slice lists in python. Indexing Lists In Python, every list with elements has a position or index. Each element of the list can be accessed or manipulated ... Read More

How does del operator work on list in Python?

Pranav Indukuri
Updated on 04-Apr-2023 12:15:55

512 Views

Lists are one of the four most commonly used data structures provided by Python. A list is a data structure in python that is mutable and has an ordered sequence of elements. Following is a list of integer values. lis= [1, 2, 3, 4, 5] print(lis) If you execute the above snippet, it produces the following output. [1, 2, 3, 4, 5] In this article, we will learn how a del operator works on a list in python. They are various scenarios where we use the del operator. The del operator The del keyword is mostly used in ... Read More

How does repetition operator work on list in Python?

Rajendra Dharmkar
Updated on 12-Jun-2020 06:19:17

2K+ Views

We are accustomed to using the * symbol to represent multiplication, but when the operand on the left side of the * is a list, it becomes the repetition operator. The repetition operator makes multiple copies of a list and joins them all together. Lists can be created using the repetition operator, *. For example, Examplenumbers = [0] * 5 print numbersOutputThis will give the output −[0, 0, 0, 0, 0][0] is a list with one element, 0.  The repetition operator makes 5 copies of this list and joins them all together into a single list. Another example using multiple ... Read More

Advertisements