[Python] How to use list 2 Reference of list value, number of elements, maximum value, minimum value

Introduction

We are advancing Python learning according to Learning Roadmap for Python Beginners on Tommy's blog. This time, I will deal with the latter half of [Introduction to Python] Summary of how to use list (Part 1).

Target person

--Those who are studying on Tomi-san's blog --For those who want to get an overview of how to use list

environment

Google Colaboratory

content of study

  1. Reference list value, slice

  2. Number of elements in the list, maximum value, minimum value

1 Refer to the value in the list

#Reference of list value No(index)
#How to refer to the list value by element No
list_num = [1,2,3,4]    #1,2,3,Create a list of 4
print(list_num[0])      #Print the left edge of the list

Execution result


1
#From the opposite
print(list_num[-1])    #Print the right edge of the list
print(list_num[-3])    #Print the third from the right of the list

Execution result


4
2
#slice
list_num = [0,1,2,3,4,5,6,7,8,9,10]    #0,1,2,3,4,5,6,7,8,9,Create a list of 10
print(list_num[1:5])                #Print from 1 to 5

Execution result


[1, 2, 3, 4]    *Note that it is acquired in the range up to one before the end element

When you want to get it in a jump

print(list_num[1:10:2])    #Print in 2 steps between 1 and 10

Execution result


[1, 3, 5, 7, 9]

When you want to get in 2D

list_two_dim =[[1,2,3],[4,5,6],[7,8,9]]
print(list_two_dim[0][1])

Execution result


2

0: 1, 2, 3 In other words, the first column of the 0th row is printed. So it will be 2 1: 4, 5, 6 The side of the row is also 0, 1, 2 from the left 2: 7, 8, 9

2 Number of elements in the list, maximum value, minimum value

#Number of elements in the list len()
list_num = [0, 1, 2, 3, 4]    #0,1,2,3,4 list creation
print(len(list_num))          #len()In list_Print the number of elements in num

Execution result


5
#Maximum value
list_num = [0,4,2,5,2,6]
print(max(list_num))
#minimum value
print(min(list_num))

Next time, I plan to add append, expend, insert and delete clear, pop, remove, del.

reference

[Introduction to Python] Summary of how to use list (Part 1)

Recommended Posts

[Python] How to use list 2 Reference of list value, number of elements, maximum value, minimum value
Summary of how to use Python list
[Python] How to use list 1
[Python] How to use list 3 Added
[Python] Summary of how to use pandas
[Python2.7] Summary of how to use unittest
[Python2.7] Summary of how to use subprocess
[Question] How to use plot_surface of python
How to use Python Kivy (reference) -I translated Kivy Language of API reference-
[python] How to display list elements side by side
[Python] How to use two types of type ()
[Python] How to put any number of standard inputs in a list
Summary of how to use MNIST in Python
[Algorithm x Python] How to use the list
How to get dictionary type elements of Python 2.7
How to use list []
How to remove duplicate elements in Python3 list
I tried to summarize how to use matplotlib of python
How to write a list / dictionary type of Python3
python3: How to use bottle (2)
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
How to identify the element with the smallest number of characters in a Python list?
How to check in Python if one of the elements of a list is in another list
How to count the number of occurrences of each element in the list in Python with weight
[Python] How to make a list of character strings character by character
[python] Summary of how to retrieve lists and dictionary elements
How to shuffle a part of a Python list (at random.shuffle)
Get the number of specific elements in a python list
[Python] Summary of how to use split and join functions
Comparison of how to use higher-order functions in Python 2 and 3
How to get a list of built-in exceptions in python
Python: How to use async with
Summary of how to use pandas.DataFrame.loc
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
Summary of how to use pyenv-virtualenv
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to use python zip function
Summary of how to use csvkit
[Python] How to use Typetalk API
Basic grammar of Python3 system (how to use functions, closures, lambda functions)
I want to use both key and value of Python iterator
[Algorithm x Python] Calculation of basic statistics (total value, maximum value, minimum value)
[Introduction to Python] How to use class in Python?
How to install and use pandas_datareader [Python]
[python] How to use __command__, function explanation
How to calculate Use% of df command