current position:Home>Initial Python tuple
Initial Python tuple
2022-01-30 15:32:01 【Solitary cold】
Little knowledge , Great challenge ! This article is participating in “ A programmer must have a little knowledge ” Creative activities .
introduction —— stay Python in , Save important data information in the project through data structure .Python The language has built-in multiple data structures , For example, a list of , Tuples , Dictionaries and collections, etc . In this class, let's talk about Python A big data structure that is of great importance in —— Tuples .
stay Python in , We can think of tuples as a special kind of list . The only difference between it and the list is : Data elements in tuples cannot be changed 【 This one doesn't change —— Not only can you not change the data items , And you can't add or delete data items !】. When we need to create a set of immutable data , Usually put this data into tuples ~
1. Of a tuple establish && visit
(1) Tuple creation :
stay Python in , The basic form of creating tuples is in parentheses “()” Enclose data elements , Use commas between the elements “,” separate . as follows :
tuple1 = ('xiaoming', 'xiaohong', 18, 21)
tuple2 = (1, 2, 3, 4, 5)
# and —— Yes, you can create empty tuples !
tuple3 = ()
# Little attention —— If the tuple you create contains only one element , And don't forget to put a comma after the element . Let it be recognized as a tuple :
tuple4 = (22, )
Copy code
(2) visit :
Tuples are similar to strings and lists , The indexes are all from 0 Start , And can be intercepted and combined . as follows :
tuple1 = ('xiaoming', 'xiaohong', 18, 21)
tuple2 = (1, 2, 3, 4, 5)
# The index in the display tuple is 1 The value of the element
print("tuple1[1]:", tuple1[0])
# Displays the index from the tuple 1 To 3 The value of the element
print("tuple2[1:3]:", tuple2[1:3])
Copy code
2. Of a tuple modify && Delete
(1) Modification of tuples :
Although it is said at the beginning that tuples are immutable , But it still has a supported operation —— Join and combine tuples :
tuple1 = ('xiaoming', 'xiaohong', 18, 21)
tuple2 = (1, 2, 3, 4, 5)
tuple_new = tuple1 + tuple2
print(tuple_new)
Copy code
(1) Deletion of tuples :
Although tuples are immutable , But it can go through del Statement to delete the entire tuple . as follows :
tuple1 = ('xiaoming', 'xiaohong', 18, 21)
print(tuple1) # Normal print tuple1
del tuple1
print(tuple1) # Because it deleted tuple1, So printing again will report an error !
Copy code
In The End!
From now on , Hold the line , Make a little progress every day , Near future , You will thank you for your efforts ! |
---|
The blogger will continue to update the basic crawler column and the actual crawler column , My friends who have read this article carefully , You can like it and comment on it . And can pay attention to this blogger , Read more about reptiles in the days to come !
If there are mistakes or inappropriate words, please point out in the comments section , thank you !
If you reprint this article, please contact me for my consent , And indicate the source and the name of the blogger , thank you !
copyright notice
author[Solitary cold],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201301532000087.html
The sidebar is recommended
- Python code reading (Part 44): find the location of qualified elements
- Elegant implementation of Django model field encryption
- 40 Python entry applet
- Pandas comprehensive application
- Chapter 2: Fundamentals of python-3 character string
- Python pyplot draws a parallel histogram, and the x-axis value is displayed in the center of the two histograms
- [Python crawler] detailed explanation of selenium from introduction to actual combat [1]
- Curl to Python self use version
- Python visualization - 3D drawing solutions pyecharts, Matplotlib, openpyxl
- Use python, opencv's meanshift and CAMSHIFT algorithms to find and track objects in video
guess what you like
-
Using python, opencv obtains and changes pixels, modifies image channels, and trims ROI
-
[Python data collection] university ranking data collection
-
[Python data collection] stock information collection
-
Python game development, pyGame module, python takes you to realize a magic tower game from scratch (2)
-
Python solves the problem of suspending execution after clicking the mouse in CMD window (fast editing mode is prohibited)
-
[Python from introduction to mastery] (II) how to run Python? What are the good development tools (pycharm)
-
Python type hints from introduction to practice
-
Python notes (IX): basic operation of dictionary
-
Python notes (8): basic operations of collections
-
Python notes (VII): definition and use of tuples
Random recommended
- Python notes (6): definition and use of lists
- Python notes (V): string operation
- Python notes (IV): use of functions and modules
- Python notes (3): conditional statements and circular statements
- Python notes (II): lexical structure
- Notes on python (I): getting to know Python
- [Python data structure series] - tree and binary tree - basic knowledge - knowledge point explanation + code implementation
- [Python daily homework] Day7: how to combine two dictionaries in an expression?
- How to implement a custom list or dictionary in Python
- 15 advanced Python tips for experienced programmers
- Python string method tutorial - how to use the find() and replace() functions on Python strings
- Python computer network basics
- Python crawler series: crawling global airport information
- Python crawler series: crawling global port information
- How to calculate unique values using pandas groupby
- Application of built-in distribution of Monte Carlo simulation SciPy with Python
- Gradient lifting method and its implementation in Python
- Pandas: how to group and calculate by index
- Can you create an empty pandas data frame and fill it in?
- Python basic exercises teaching! can't? (practice makes perfect)
- Exploratory data analysis (EDA) in Python using SQL and Seaborn (SNS).
- Turn audio into shareable video with Python and ffmpeg
- Using rbind in python (equivalent to R)
- Pandas: how to create an empty data frame with column names
- Talk about quantifying investment using Python
- Python, image restoration in opencv - CV2 inpaint
- Python notes (14): advanced technologies such as object-oriented programming
- Python notes (13): operations such as object-oriented programming
- Python notes (12): inheritance such as object-oriented programming
- Chapter 2: Fundamentals of python-5 Boolean
- Python notes (11): encapsulation such as object-oriented programming
- Python notes (10): concepts such as object-oriented programming
- Gradient lifting method and its implementation in Python
- Van * Python | simple crawling of a site course
- Chapter 1 preliminary knowledge of pandas (list derivation and conditional assignment, anonymous function and map method, zip object and enumerate method, NP basis)
- Nanny tutorial! Build VIM into an IDE (Python)
- Fourier transform of Python OpenCV image processing, lesson 52
- Introduction to python (III) network request and analysis
- China Merchants Bank credit card number recognition project (Part I), python OpenCV image processing journey, Part 53
- Python practice - capture 58 rental information and store it in MySQL database