Found 27104 Articles for Server Side Programming

What is the maximum length of string in Python?

Pythonic
Updated on 30-Jul-2019 22:30:20

4K+ Views

Maximum length of a string is platform dependent and depends upon address space and/or RAM. The maxsize constant defined in sys module returns 263-1 on 64 bit system. >>> import sys >>> sys.maxsize 9223372036854775807 The largest positive integer supported by the platform's Py_ssize_t type, is the maximum size lists, strings, dicts, and many other containers can have.

What is the maximum value of float in Python?

Pythonic
Updated on 30-Jul-2019 22:30:20

638 Views

In sys module, a struct sequence (tuple of named elements) called float_info has been defined. In this structure, an element max returns maximum representable finite float number. >>> import sys >>> sys.float_info.max 1.7976931348623157e+308

How to sort a dictionary in Python by values?

Pythonic
Updated on 30-Jul-2019 22:30:20

2K+ Views

Standard distribution of Python contains collections module. It has definitions of high performance container data types. OrderedDict is a sub class of dictionary which remembers the order of entries added in dictionary object. When iterating over an ordered dictionary, the items are returned in the order their keys were first added. >>> from collections import OrderedDict >>> D = {5:'fff', 3:'ttt', 1:'ooo', 4:'bbb', 2:'ddd'} >>> OrderedDict(D.items())  OrderedDict([(5, 'fff'), (3, 'ttt'), (1, 'ooo'), (4, 'bbb'), (2, 'ddd')]) We also need to us sorted() function that sorts elements in an iterable in a specified order. The function takes a function ... Read More

How to sort a dictionary in Python by keys?

Pythonic
Updated on 30-Jul-2019 22:30:20

494 Views

Standard distribution of Python contains collections module. It has definitions of high performance container data types. OrderedDict is a sub class of dictionary which remembers the order of entries added in dictionary object. When iterating over an ordered dictionary, the items are returned in the order their keys were first added. >>> from collections import OrderedDict >>> D = {5:'fff', 3:'ttt', 1:'ooo', 4:'bbb', 2:'ddd'} >>> OrderedDict(D.items())  OrderedDict([(5, 'fff'), (3, 'ttt'), (1, 'ooo'), (4, 'bbb'), (2, 'ddd')]) We also need to use sorted() function that sorts elements in an iterable in a specified order. The function takes a function ... Read More

How to iterate through a dictionary in Python?

Sarika Singh
Updated on 18-Aug-2022 11:42:27

11K+ Views

Dictionaries are a valuable and frequently used data structure in Python. This article tells us how to traverse through a dictionary while performing operations on its key-value pairs. Using dict.items() Method Python's dict.items() method allows you to loop through the dictionary. Each repetition will provide you with both the key and value of each item. Example Following is an example to iterate through a dictionary using dict.items() method − dictionary = { 'Novel': 'Pride and Prejudice', 'year': '1813', 'author': 'Jane Austen', 'character': 'Elizabeth Bennet' ... Read More

How to print all the values of a dictionary in Python?

Sarika Singh
Updated on 23-Aug-2023 13:04:37

84K+ Views

Python has a built-in method called values() that returns a view object. The dictionary's values are listed in the view object. We can use the values() method in Python to retrieve all values from a dictionary. Python's built-in values() method returns a view object that represents a list of dictionaries containing every value. This article explains about the various ways to print all the values of a dictionary in Python. Using dict.values() Method Python's dict.values() method can be used to retrieve the dictionary values, which can then be printed using the print() function. Example Following is an example to print ... Read More

How to print all the keys of a dictionary in Python

Sarika Singh
Updated on 23-Aug-2023 12:57:45

96K+ Views

An unordered collection of data values is what a Python dictionary is. A Python dictionary contains a key: value pair, in contrast to other data structures that only include one value per entry. This article explains about the various ways to print all the keys of a dictionary in Python. Using dict.keys() Method Python's dict.keys() method can be used to retrieve the dictionary keys, which can then be printed using the print() function. A view object that shows a list of every key in the dictionary is the result of the dict.keys() method. The dictionary's elements can be accessed using ... Read More

How do we specify the buffer size when opening a file in Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 11:28:45

5K+ Views

File handling is a critical aspect of seamless data management in the realm of computer programming. There are times when choosing the buffer size is crucial when working with files, particularly when handling huge files or carrying out certain actions that need efficient memory utilization. Because of its integrated file-handling features, the strong and flexible programming language Python gives developers the freedom to choose the buffer size when opening files. This extensive essay will examine how to set the buffer size in Python when opening a file. In order to explain the ideas, we will go over them step-by-step and ... Read More

What does the 'U' modifier do when a file is opened using Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 10:23:24

716 Views

File handling plays a pivotal role in efficiently managing data in the realm of computer programming. Python, being a versatile and powerful language, equips developers with robust mechanisms for reading and writing files seamlessly. When working with files, Python offers a range of modifiers that allow for fine-tuning the behavior of the file object. One such modifier, the 'U' modifier, holds particular significance as it influences the way Python handles line endings when reading a file in text mode. In this comprehensive exploration, we will delve into the intricacies of the 'U' modifier and its implications when opening files in ... Read More

What does the 'b' modifier do when a file is opened using Python?

Sarika Singh
Updated on 14-Nov-2022 08:24:56

11K+ Views

If we open a file in oython using the b modifier. The file is opened in binary mode using the 'b' modifier. Any file whose format doesn't consist of readable characters is referred to as a "binary" file. Binary files include audio files like MP3s, text formats like Word or PDF, and image files like JPEGs or GIFs. Files are automatically opened in text mode in Python. When choosing a mode, include the letter "b" for binary mode. By default, the open() function opens a file in text format. As a result, the "wb" mode opens the file in binary ... Read More

Advertisements