python-day03

Tuple format

  (Element 1, element 2, element 3, ...)

  Elements can be accessed, but can not be modified

Nested list

  List name [] []

print (id (variable name)) to obtain the address of the variable value

List, an ordered set of tuples, dictionaries unordered collections

dictionary

  The only type of mapping python

  format

    Dictionary name = { 'key', 'value', ...} or dictionary name = dict ( 'key,' value ')

Immutable type: integer, string, a tuple

Variable types: lists, dictionaries

  use

    By looking for the value of the key, the key can only be immutable

    print (name dictionary [ 'key'])

increase

  Name dictionary [ 'key'] = 'value' if the key is present, then the new value overwrites the old value does not exist, add to the dictionary

  Dictionary name .setdefault ( 'key', 'value') if the key is present, no effect, does not exist, add to the dictionary and return values

check

  print (name dictionary [ 'key'])

  Dictionary name .keys () to find all the keys

  Dictionary name .values ​​() Find all values

  Dictionary name .items () to find all keys

change

  Name dictionary [ 'key'] = 'new value'

  Dictionary a.update (dictionary b) adding to the dictionary b keys in a dictionary, if the same key, the original value of the coverage

delete

  Dictionary name .clear () clears dictionary

  del dictionary name [ 'key'] Delete the specified key

  Dictionary name .pop ( 'key') to delete the specified key, and returns a value dictionary name .pop () to delete a random key

  Dictionary name .popitem () delete a random set of keys, and returns a tuple method

Other operations

  dict.fromkeys ([ 'key 1', 'key 2', ..], 'value') of the specified value is assigned to the specified key

Nested dictionary

  Dictionary name = { 'key': {}, ..}

Sequence

  sorted (dictionary name) button from small to large

  sorted (dictionary name .values ​​()) by value from small to large

Dictionary traversal

  for i in dictionary name:

    print (i, Dictionary names [i])

  for i in the dictionary name .items () returns a value tuple type

Character Transfer

  \' apostrophe

  \'' Double quotes

  \ T Tab

  \ N newline

  \\ slash down

String sections

  'String' [;]

in judgment

  'Partial string' in 'string'

The method of connection string

  · ''. Join () connected to one string for

String built-in method

  count () calculates the number of occurrences string

  capitalize () first letter capitalized

  center () center

  endwith () to determine whether an end with the specified content, in line with True, and vice versa Flase

  startwith () to determine whether to start with a specified content, in line with True, and vice versa Flase

  How many spaces expandtabs (tabsize =) Set the escape character tabs

  find () search string from left to right, which returns the index to find the value, a value of -1 is not found

  format () formatted output

   name = ’I am {name}'

   name.format(name=' ')

  format_map () parameter as a dictionary

  index () to find the string index value is returned, not found error

  .isalnum () determines whether the numbers and letters, and non-empty, is True

  .isdecimal () determines whether or contain only numbers, and non-empty, is True

  .isalpha () determines whether or contain only letters, and non-empty, is True

  .isdigit () determines whether an integer

  .isspace () determines whether only contains space, tab, newline

  .istitle () to determine whether the first letter capitalized, and followed by lowercase letters of the word

  .isidentifier () determines illegal identifier

  Whether .islower () are judged to lowercase

  Whether .isupper () to determine both uppercase

  .lower () uppercase to lowercase

  .upper () becomes uppercase lowercase

  .swapcase () uppercase to lowercase, uppercase lowercase change

  .ljust () Left

  .rjust () right justified

  .strip () to delete the character left and right blank

  .lstrip () to delete the character left blank

  .rstrip () Delete character right margin

  .replace ( 'old', 'new') replacement string

  .rfind () to find the string from right to left and returns the index value

  .split () divided by parameter a delimiter string, it returns a list of

  .rsplit () right to left, divided by a parameter string delimiter, returns a list of

  .title () first letter capitalized, followed by lower case letters of the word

Guess you like

Origin www.cnblogs.com/324fch/p/11701424.html