- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10784 Articles for Python
43K+ Views
In this article, we will show you how to get a list of all the keys from a Python dictionary using various methods. We can get the list of all the keys from a Python dictionary using the following methods − Using dict.keys() method Using list() & dict.keys() function Using List comprehension Using the Unpacking operator(*) Using append() function & For loop Assume we have taken an example dictionary. We will return the list of all the keys from a Python dictionary using different methods as specified above. Method 1: Using dict.keys() method In Python Dictionary, the dict.keys() ... Read More
29K+ Views
In this article, we will show you how to get a value for the given key from a dictionary in Python. Below are the 4 different methods to accomplish this task − Using dictionary indexing Using dict.get() method Using keys() Function Using items() Function Assume we have taken a dictionary containing key-value pairs. We will return the value for a given key from a given input dictionary. Method 1: Using dictionary indexing In Python, we can retrieve the value from a dictionary by using dict[key]. Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired ... Read More
1K+ Views
A dictionary maintains mappings of unique keys to values in an unordered and mutable manner. In python, dictionaries are a unique data structure, and the data values are stored in key:value pairs using dictionaries. Dictionaries are written with curly brackets and have keys and values. Dictionaries are now ordered as of Python 3.7. Dictionaries in Python 3.6 and before are not sorted. Example In the following example, companyname, and tagline are the keys, and Tutorialspoint, simplyeasylearning are the values respectively. thisdict = { "companyname": "Tutorialspoint", "tagline" : "simplyeasylearning", } print(thisdict) Output The above ... Read More
2K+ Views
A dictionary is a Python is a container that maintains mappings of unique keys to values in an unordered and mutable manner. Data values are stored in key:value pairs using dictionaries. Dictionaries are written with curly brackets and have keys and values. Dictionaries are now ordered as of Python 3.7. Dictionaries in Python 3.6 and before are not sorted. Example This example shows the working of a dictionary in python. thisdict = { "companyname": "Tutorialspoint", "tagline" : "simplyeasylearning", } print(thisdict) Output The above code produces the following results {'companyname': 'Tutorialspoint', 'tagline': 'simplyeasylearning'} ... Read More
23K+ Views
List and Tuple in Python are the class of data structure. The list is dynamic, whereas the tuple has static characteristics. We will understand list and tuple individually first and then understand how to convert a list into a tuple. List Lists are a popular and widely 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= [10, 20, 30, 40, 50] print(lis) If you execute the above snippet, it produces the following output − [10, ... Read More
28K+ Views
A tuple is an ordered and immutable collection of Python objects separated by commas. Like lists, tuples are sequences. Tuples differ from lists in that they can't be modified, whereas lists can, and they use parentheses instead of square brackets. tup=('tutorials', 'point', 2022, True) print(tup) If you execute the above snippet, produces the following output − ('tutorials', 'point', 2022, True) In this article, we will discuss how to index and slice tuples in python. Indexing Tuples In Python, every tuple with elements has a position or index. Each element of the tuple can be accessed or manipulated by ... Read More
5K+ Views
A tuple is an ordered and immutable collection of Python objects separated by commas. Like lists, tuples are sequences. Tuples differ from lists in that they can't be modified, whereas lists can, and they use parentheses instead of square brackets. tup=('tutorials', 'point', 2022, True) print(tup) If you execute the above snippet, produces the following output − ('tutorials', 'point', 2022, True) In this article, we discuss about the use of the del operator on a tuple. The del operator The del keyword is mostly used in Python to delete objects. Because everything in Python is an object, the del ... Read More
4K+ Views
A tuple is an ordered and immutable collection of Python objects separated by commas. Like lists, tuples are sequences. Tuples and lists differ in that tuples cannot be altered, although lists may, and tuples use parentheses whereas lists use square brackets. tup=('tutorials', 'point', 2022, True) print(tup) If you execute the above snippet, produces the following output − ('tutorials', 'point', 2022, True) In this article, we discuss different ways to repeat a tuple in python. Repetition operation on tuples. To repeat the same tuple for a particular number of times, then the following ways can be used. Using ... Read More
1K+ Views
A tuple is a collection of python objects that are separated by commas which are ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists are, that tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. tup=('tutorials', 'point', 2022, True) print(tup) If you execute the above snippet, produces the following output − ('tutorials', 'point', 2022, True) In this article, we will look at how to concatenate operator works on tuples in python. Concatenate operation on tuples Concatenation of tuples in python means joining two or more tuples ... Read More
1K+ Views
In this article, we discuss about the ‘in’ operator and how it works on tuples in python. Before moving on, we will discuss about tuples first. 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 ... Read More