Python Basics-Basic data type (sets (collection)-immutable data)

Source: Internet
Author: User

Python Basics-Basic data type (number (numeric) string (string) list (list) Tuple (tuple) sets (collection) Dictionary (dictionary))

There are six standard data types in the Python3:
Number (numeric)
String (String)
List (lists)
Tuple (tuple)
Sets (collection)
Dictionary (dictionary)

Among the six standard data types of Python3:
Immutable data (four): Number, String (string), tuple (tuple), sets (set);
Variable data (two): List, Dictionary (dictionary).


Python3 Basic data types
Variables in Python do not need to be declared. Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned. In Python, a variable is a variable, it has no type, and what we call "type" is the type of object in memory that the variable refers to.
Variable = object

1. Assigning values to multiple variables
Python allows you to assign values to multiple variables at the same time.
For example:
A = b = c = 1
The above example creates an integer object with a value of 1 and three variables pointing to the same memory location.

2. You can also specify multiple variables for multiple objects.
For example:
A, b, C = 1, 2, "Runoob"
For the above example, two integer objects 1 and 2 are assigned to variables A and B, and the string object "Runoob" is assigned to the variable C.


One, set (set)
a collection (set) is a sequence of unordered, non-repeating elements.
The basic function is to test the membership and remove duplicate elements.
You can create a collection using the curly braces {} or the set () function, note: Creating an empty collection must be set () instead of {}, because {} is used to create an empty dictionary.
To Create a format:
parame = {value01,value02,...}
or
Set (value)


Instance:

#!/usr/bin/Python3 Student= {'Tom','Jim','Mary','Tom','Jack','Rose'} print (student) # output set, duplicate elements are automatically removed # member testif('Rose' inchstudent): Print ('Rose in the collection')Else: Print ('Rose is not in the collection.') # Set can perform set operation a=Set('Abracadabra') b=Set('Alacazam') print (a) print (a-b) # A and B difference set print (a|b) # A and B of the set print (a&b) The intersection of # A and B print (a^b) # A and B do not exist in the same element above the instance output result: {'Mary','Jim','Rose','Jack','Tom'}rose in the collection {'b','a','C','R','D'}{'b','D','R'}{'L','R','a','C','Z','m','b','D'}{'a','C'}{'L','R','Z','m','b','D'}



Python Basics-Basic data type (sets (collection)-immutable data)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.