Formatting of strings
Insert the%s into the string as a placeholder, and then define the insert variable.
Arithmetic operations
% modulus to judge odd even
/division has less than sign
The integer division is returned by dividing the integers
Logical operations
and
Or
Not
' Str '. IsDigit () is the ability to determine whether a string can be converted to a number
Boolean operations are false in the following cases!
[] Empty list
{} Empty Dictionary
() empty tuple, empty collection
' Empty string '
0
bitwise OPERATION = = binary operation
The list of copy-shallow copy relationships with deep copy is used in memory placeholder IDs to understand!
Fromkeys () in the dictionary
Create a new dictionary from the sequence key and value set to value.
Describe
The Python Dictionary (Dictionary) Fromkeys () function is used to create a new dictionary, which is the key to the dictionary of elements in the sequence SEQ, and value is the initial value corresponding to all keys in the dictionary.
Grammar
Fromkeys () method syntax:
Dict.fromkeys (seq[, value]))
Parameters
- SEQ--Dictionary key value list.
- Value--an optional parameter that sets the values of the key sequence (seq).
return value
The method returns a list.
Instance
The following example shows how the Fromkeys () function is used:
#!/usr/bin/python
Seq = (' name ', ' age ', ' sex ')
Dict = Dict.fromkeys (seq)
Print "New Dictionary:%s"% str (DICT)
Dict = Dict.fromkeys (seq, 10)
Print "New Dictionary:%s"% str (DICT)
The result of the above example output is:
New Dictionary: {' age ': none, ' name ': none, ' Sex ': none}
New Dictionary: {' age ': Ten, ' name ': ten, ' Sex ': 10}
Python Full stack Python Foundation (quad) OP copy