directory

  • A brief introduction to the Python zip function
  • Use the Python zip function
  • Description and use of the Python *zip function
  • Four. Guess you like it

Recommended path for learning Python: Python Learning Directory >> Python Basics

A brief introduction to the Python zip function

The zip function takes an iterable object as an argument, packs the corresponding elements into tuples, and returns an object composed of these tuples. The result can be directly converted to a list, which saves a lot of memory.

Iterable - An iterator object. The zip function can have one or more iterators. Zip ([iterable,...]); zip([iterable,...]; )Copy the code

Use the Python zip function

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file: Python zip function. py @time :2021/3/22 23:37 @motto: A thousand miles without a single step, a river without a small stream, the wonderful life of the program needs to be accumulated with perseverance! "" "list1 = [" a ", "b", "c", "d", "E"] list2 = 50.5] [1, False, result = zip (list1, list2) print (type (result) Print (list (result)) "' output: < class 'zip' > [(' a ', 1), (" b", False), (50.5) 'c'] ' ' 'Copy the code

Note: If two iterators have different lengths, the shortest iterator length is automatically matched!

Description and use of the Python *zip function

If the zip function is compressed, then the *zip function is decompressed, the return value of the function is two-dimensional matrix, the code example is as follows:

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file: Python zip function. py @time :2021/3/22 23:37 @motto: A thousand miles without a single step, a river without a small stream, the wonderful life of the program needs to be accumulated with perseverance! "" "list1 = [" a ", "b", "c", "e", "fasf"] list2 = 50.5] [1, False, a1, a2 = zip zip (list1, list2) (*) print (list (a1) Print (list (a2)) "' output: [' a ', 'b', 'c'] [1, False, 50.5] ' ' 'Copy the code

Note: If two iterators have different lengths, the shortest iterator length is automatically matched!

Four. Guess you like it

  1. Introduction of Python
  2. Python Pycharm Anacanda difference
  3. Python2.x and python3. x, how to choose?
  4. Python Configuration Environment
  5. Introduction to Python Hello World
  6. Python code comments
  7. Python Chinese encoding
  8. What is Anaconda? Anconda download the installation tutorial
  9. Pycharm prompt: this license **** has been cancelled
  10. Pycharm Sets the development template/font size/background color

Python zip functions

This article is published by the blog – Ape Say Programming Ape Say programming!