Description Data Type python


# Python is no need to declare variables. Each variable must be assigned before use variable assignment after the variable will be created.
# Python3 There are six standard data types: Numbers (digital) String (String) List (list) Tuple (component) Sets (collections) Dictionaries (Dictionary)

# a Numbers (digital)

# Python 3 support int, float, bool, complex (complex
A, B, C, D = 20 is, 5.5, True,. 4 + 3j
Print (type (A), type (B), type (C), type (D))
# The other calculation, here you just write something special
print (2 // 4) # division (//) get an integer,
Print (2/4) # division (/) always returned a float
print (2 ** 5) # multiply Fang

# string (string)
S = 'Yes, of He doesn \' t '
Print (S, of the type (S), len (S))
Print (r'C: \ some \ name') # If you do not want anti slash escape occurs, can be added in front of a string r, represents the original string:

word1 = 'ILove'
word2 = 'the Python'
Print (word1 + word2, word2 *. 3) # + operator may use a string string connections together, or with repeated operator *
print (word2 [0], word2 [5]) # Python strings have two indexing methods, the first from left to right, sequentially increases from 0; the second is from right to left, from the - 1 in order to start to reduce.
print (word2 [1: 5] ) # slicing string, the substring acquisition period. Two indices separated by a colon, in the form of a variable [head superscript: Tail index], if omitted, no slice.

# List (list)

[ 'HIM', 25, 100, 'HER'] A = # similar array
Print (A)
Print (A + [. 6,. 7,. 8]) # list also supports operating in series, using the + operator
a [2: 3] = [ 13] # and cutting a different character, the cutting list may change elements
Print (a)


# tuple (tuple)

# tuple (tuple) and a list of similar, except that the elements of the tuple is not modify. Tuple written in parentheses, separated by commas between the elements.
A = (1999, 2019, 'Physics', 'Math')
Print (A, type (A), len (A))
# tuple structure contains zero or one element is a particular problem, so there are some additional syntax rules
tup1 = () # empty tuple
tup2 = (20,) # an element necessary to add a comma after the element
# string, list and tuple belongs sequence (sequence)

# sets (set)
# collection (set) is a unordered set of elements is not repeated.
# Basic function is to be a member of testing and eliminating duplicate elements.
Student = { 'Tom', 'Jim', 'Mary', 'Tom', 'Jack', 'Rose'}
Print (Student) # repetitive elements are automatically removed
print ( 'Rose' in student) # membership testing ( members of the test)
# can use braces or set () function creates a collection set,
# NOTE: create an empty collection must be set () instead of {}, {because} is used to create an empty dictionary.
# Set a set operation
A = SET ( 'abcdefgabc')
Print ( "A set as:", A)
b = SET ( 'abcdabc')
Print ( "b set as:", b)
Print ( "A and b the difference between the set: ", a - b) # a and b are set difference
print (" a and b of the union: ", a | b) # a and b and set
print (" a and b of the intersection: " , a & b) # a and b the intersection
print ( "a and b are not simultaneously present in the element:", a ^ b) # a and b are not simultaneously present in the element

# dictionaries (Dictionary)
# dictionary is a mapping types (mapping type), it is an unordered keys: The value of the collection.
dic = {} # Create empty dictionary
Tel = { 'Jack': 1557, 'Tom': 1320 is, 'Rose': 1886}
Print (Tel)
print (tel [ 'Jack'] ) # main actions: by key inquiries
del tel [ 'Rose'] # delete a key-value pair
tel [ 'Mary'] = 4127 # to add a key-value pair
Print (tel)
tel [ 'Mary'] = 3434 # key to change a
Print (Tel)
Print (the sorted (tel.values ())) # value sorted by ascending
print (list (tel.keys ()) ) # returns all key consisting of List
Print ( 'Mary' not in tel) # member of the test
print ( 'Tom' in tel)






Guess you like

Origin www.cnblogs.com/YLTzxzy/p/11331135.html