Use curly braces to initialize a Set in Python

前端 未结 4 1184
别跟我提以往
别跟我提以往 2020-12-13 11:47

I\'m learning python, and I have a novice question about initializing sets. Through testing, I\'ve discovered that a set can be initialized like so:

my_set          


        
4条回答
  •  眼角桃花
    2020-12-13 12:20

    Compare also the difference between {} and set() with a single word argument.

    >>> a = set('aardvark')
    >>> a
    {'d', 'v', 'a', 'r', 'k'} 
    >>> b = {'aardvark'}
    >>> b
    {'aardvark'}
    

    but both a and b are sets of course.

提交回复
热议问题