Sets in Python

 Set:

  • The set data type is used to store unique values and displayed by ordered sequence manner.
  • These items are mutable, that means can change the sets.
  • It is denoted by curly braces {} but if calling the index with value means not possible.

Syntax:

  1. Declaring value into the set:

    Variable_name={item1,item2,...item n}

    Example:

    a={1000,’Kurshitha’,’female’,450}

Example program for print the set of elements:

  1. a={8,5,1,3,7}

    print(a)

Output:

Insert an item into the set:

  • To insert an element in the set is used add() function.

  1. a={8,5,1,3,7}

    a.add(15)

    print(a)

Output:

Insert number of items at a time into the set:

  • To insert number of element in set is used update() function.

  1. a={8,5,1,3,7}

    a.update([15,10,11])

    print(a)

Output:

Share:

No comments:

Post a Comment

Popular Posts

Search This Blog

Powered by Blogger.

Service Support

Need our help to Learn or Post New Concepts Contact me

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me