python data types: digital Nubmer / string String / list List / tuples Tuple / collection Set / Dictionary Dictionary

#python the standard data types of digital Nubmer string String List List tuple Tuple Set Dictionary set the Dictionary 

# single variable assignment
countn00 = '10'; # integer
countn01 = '100.0' # floating point
countn02 = "double right"; # string
countn03 = '10'; # number
#print ( "integer =" + countn00, "Floating Point =" + countn01, "character string =" + countn02, "digital =" + countn03)

# plurality of variable assignments
a, b, c, d, e, f =double right"
#Print (A, B, C, D, E, F)
--------------- -------------------------------------------------- ----------------------

# list - query
Studen = [ "pig", "dog", "cow", "snake"]
#Print (Studen [ 2])

# list - Add - first way
Studen.append ( "you are so bad."
#Print (Studen)

# List - Add the specified index location - a second embodiment
Studen [2] = "ant"
#Print (Studen);

# Add collection element - a third mode
Studen.insert (4, "Go")

# list - delete
Studen_pop = Studen.pop (3)
#Print (Studen)

# get a list of elements - not out of bounds ensure that the index may len (Studen) [- 1] or Studen [-1 ]
len (Studen)
--------------------------------------------- ------------------------------------------
# Tuple
Strudens = ( "you", "I", "he", "she");
Print (Strudens [2]);

# ordered [list of tuples] tuple Once the initialization can not be changed
classmates = ( ' micheal ',' Bob ',' Tracy ')
Print (Classmates [0])

# in [tuples] tuple added in a set may be changed a [ set ] which properties are possible;
classmatesa = (' micheal ' , 'Bob', [ 'A', 'B'])
classmatesa [2] [0] = 'C'
classmatesa [2] [. 1] = 'D'
Print (classmatesa)
# Summary: 1: list may be modified, not only read the ancestral Amendment 2: symbols are not the same; the use of tuples () list uses parentheses [] brackets; tuples can change the properties thereof oh
---------------------------------------------------------------------------------------
# Set: intersection and set difference set deduplication element
A = SET ( "1234567890");
B = SET ( "234");

# intersection operator
C = A & B;
Print (C);

# and symbol set is intended: joinder which (remove duplicate only element)
D = a | B;
Print (D);

# difference symbol set is intended: a Comparative B more elements
E = ab &;
Print (E);

# deduplication element set method
new = set ( A)
Print (new new);
------------------------------------------- --------------------------------------------
# Dictionary
Map = { "1": "pig", "2": "dog", "3": "Small Meow"}
Print (the Map [ ". 1"]);

# Add dictionary
Map [ "4"] = "lamb";
Print (the Map [ ". 4"])

Guess you like

Origin www.cnblogs.com/shuangquan/p/10954534.html