Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report