Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of parentheses () [] {} in Python

Shulou Source: shulou.com Published: 2022-06-02 17:22:18 09月26日 Update

This article will explain in detail the usefulness of parentheses () [] {} in Python. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Foreword:

There are three main data types for Python: dictionaries, lists, and tuples. They are represented by curly braces, square brackets and parentheses respectively.

Such as:

Dictionary: dic= {'aqiaqizuo 12 thecontrolling breadcracy 34}.

List: list= [1, 2, 3, 4]

Tuple: tup= (1, 2, 3, 4)

The three most common types of parentheses in the python language are ∶ parentheses (), square braces [], and curly braces, also known as curly braces {}. They also play different roles, representing different python basic built-in data types.

1. Parentheses in python ()

Represents the tuple data type, which is an immutable sequence. The creation method is simple and is mostly enclosed in parentheses.

> tup = (1Personality 2) > tup (1) # empty tuple () > 55 parentheses in (55,) 2, python

Represents the list list data type, and a list is a variable sequence. The creation method is simple and special, like the following:

> list ('python') ['paired,' yearly, 'tasked,' hacked, 'oval,' n'] 3, python braces {} curly braces

Represents the data type of the dict dictionary, which is made up of groups of key pairs. The colon ∵ separates the key from the value, and the comma '∵' separates the group.

The method created with curly braces is as follows:

> dic= {'jon':'boy','lili':'girl'} > dic {' lili':'girl','jon':'boy'} > > about "what is the use of brackets () [] {} in Python" this article ends here. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it out for more people to see.

Tags: Parentheses brackets data types representatives dictionaries methods articles sequences more variable different good practical same function content colons preface common Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB vpn Shulou Tech Info NVidia Apple