Found 27104 Articles for Server Side Programming

How do we use double quotation in Python?

Niharika Aitam
Updated on 15-May-2023 13:24:16

460 Views

Double quotes are used to represent a string or a character as well as can be used in the print function to print the defined statement as the output. The functionality of the single quotes and double quotes is same. We can use any type quotes as per our requirement. The following is the syntax to create a string using the double quotes in the python programming language. str = “text” Where, “ ” are the double quotations text is the data to be in string format Example Let’s see an example to understand the functionality and ... Read More

How I can dump a Python tuple in JSON format?

Niharika Aitam
Updated on 15-May-2023 12:46:09

782 Views

JSON can be abbreviated as JavaScript Object Notation. It means a script of a text file in a programming language to transfer and store the data. It is supported by the python programming language using a built-in package named json. It’s text is given in the quoted string format which contains a key and value within the curly braces{} which looks like a dictionary. To access a JSON document using python we have to import the json package. In this package we have a method named dumps() which is used to convert the python tuple objects into the Java ... Read More

List vs tuple vs dictionary in Python

Niharika Aitam
Updated on 15-May-2023 11:12:02

24K+ Views

In python there are different types of data structures. Among them list, tuple, dictionary. All these three are used to store the data in the python programming language. What is a List? List is one of the data structures available in python which is used to store multiple values in a single data structure. We can create a list in Python using the square braces[ ]. It is mutable which means that we can modify a list once it is created. It takes multiple elements of different data types such as int, float, str etc which are separated by ... Read More

What are different types of quotes in Python?

Niharika Aitam
Updated on 09-Sep-2023 09:50:36

5K+ Views

There are different types of quotes in Python. Each quotation is used in different scenarios as per the requirement. The following are the different types of quotations which we can use in the python programming language. Single quotes Double quotes Triple quotes What are Single quotes? Single quotes (' ') are used to create strings and characters in Python programming. Since the print() function accepts string values we can directly pass values to it wrapping them within the single quotes. Example In this example, we will create a string using the single quotes and assign it to the ... Read More

How to create an empty tuple in Python?

Niharika Aitam
Updated on 09-Sep-2023 15:17:25

7K+ Views

Tuple is one of the data structures of the Python programming language. It is used to store multiple values separated by commas in an ordered manner. It is immutable in the sense that once the tuple is created cannot perform any operations like deleting, appending etc. The elements in the tuple can be int, float, string, binary data types and it allows duplicates of the elements. It uses indexing for accessing the elements. It allows a single element to be in tuple.Indexing is the concept used for accessing the elements from particular data structures. There are two ways of performing ... Read More

How to create an empty dictionary in Python?

Niharikaa Aitam
Updated on 15-May-2023 10:27:54

3K+ Views

The dictionary is the data structure available in python. Dictionaries are also known as associative memories or associative arrays. It is represented by curly braces {}. It stores the data in the form of key and value pairs. Data from a dictionary can be accessed by its key, unlike other data structures which use indexes. To retrieve the value associated with a particular key, one must use index values. As keys in dictionaries are unique, any immutable object such as tuples or strings can be used to identify them. However, values stored in dictionaries do not need to be ... Read More

How to create an empty list in Python?

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

495 Views

You can create empty list object by giving no elements in square brackets in assignment statement. Empty list object is also created by list() built-in function without any arguments >>> L1 = [] >>> L1 [] >>> L1 = list() >>> L1 []

How to create Python dictionary from list of keys and values?

Pythonic
Updated on 08-Nov-2023 00:37:00

22K+ Views

If L1 and L2 are list objects containing keys and respective values, following methods can be used to construct dictionary object. Zip two lists and convert to dictionary using dict() function >>> L1 = ['a','b','c','d'] >>> L2 = [1,2,3,4] >>> d = dict(zip(L1,L2)) >>> d {'a': 1, 'b': 2, 'c': 3, 'd': 4} Using dictionary comprehension syntax >>> L1 = ['a','b','c','d'] >>> L2 = [1,2,3,4] >>> d = {k:v for k,v in zip(L1,L2)} >>> d {'a': 1, 'b': 2, 'c': 3, 'd': 4}

In Python how to create dictionary from two lists?

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

311 Views

If L1 and L2 are list objects containing keys and respective values, following list comprehension syntax can be used to construct dictionary object. >>> L1 = ['a','b','c','d'] >>> L2 = [1,2,3,4] >>> d = {L1[k]:L2[k] for k in range(len(L1))} >>> d {'a': 1, 'b': 2, 'c': 3, 'd': 4}

How do we define dictionary in Python?

Pythonista
Updated on 25-Feb-2020 11:23:19

131 Views

Dictionary object is an unordered collection of key-value pairs, separated by comma and enclosed in curly brackets. Association of value with key is marked by : symbol between them.>>> D1={'a':1,'b':2,'c':3}Key can appear in a dictionary object only once, whereas single value can be assigned to multiple keys. Key should be of immutable data type i.e. number, string or tuple.>>> D2={1:'aaa', 2:'bbb', 3:'ccc'} >>> D3={(10,10):'x1', (20,20):'x2'} >>> D4={'Microsoft':['MS Office', 'Windows', 'C#'], 'Oracle':['Oracle', 'Java', 'MySQL']}

Advertisements