python創建空元組_用Python創建空元組

python創建空元組

Python | 空元組 (Python | empty tuple)

In python, we can also create a tuple without having any element. An empty tuple is created using a pair of round brackets, ().

在python中,我們也可以創建一個沒有任何元素的元組 。 使用一對圓括號()創建一個空元組

Syntax:

句法:

    tuple_name = ()

Example 1:

范例1:

# Python empty tuple creation`
tuple1 = () 
# printing tuple 
print("tuple1: ", tuple1)
# printing length
print("len(tuple1): ", len(tuple1))
# printing type
print("type(tuple1): ", type(tuple1))

Output

輸出量

tuple1:  ()
len(tuple1):  0
type(tuple1):  <class 'tuple'>

Example 2:

范例2:

We can also create an empty tuple by initializing the tuple with tuple() – generally this method is used to clear/reinitialize the tuple.

我們也可以通過使用tuple()初始化元創建一個空元 組 -通常,此方法用于清除/重新初始化元組。

# Python empty tuple creation`
tuple1 = tuple() 
# printing tuple 
print("tuple1: ", tuple1)
# printing length
print("len(tuple1): ", len(tuple1))
# printing type
print("type(tuple1): ", type(tuple1))
print()
# non-empty tuple
tuple2 = (10, 20, 30, 40, 50)
# printing original tuple
print("tuple2: ", tuple2)
print()
# reinitialize
tuple2 = tuple()
print("After reinitialize...")
# printing tuple 
print("tuple2: ", tuple2)
# printing length
print("len(tuple2): ", len(tuple2))
# printing type
print("type(tuple2): ", type(tuple2))

Output

輸出量

tuple1:  ()
len(tuple1):  0
type(tuple1):  <class 'tuple'>
tuple2:  (10, 20, 30, 40, 50)
After reinitialize...
tuple2:  ()
len(tuple2):  0
type(tuple2):  <class 'tuple'>

翻譯自: https://www.includehelp.com/python/empty-tuple-creation.aspx

python創建空元組

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540744.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540744.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540744.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

共享馬扎的火爆,原來是一場營銷!

如今&#xff0c;人們的生活仿佛已經被“共享化”&#xff1a;上班有共享單車、睡覺有共享床鋪、商場有共享充電寶、去機場有共享巴士……好像除了男女朋友是自己的&#xff0c;其他都要共享了&#xff01;哎&#xff0c;不對&#xff01;前些日子&#xff0c;竟然還真有了共享…

什么是CDP(連續數據保護)?

CDP&#xff1a;連續數據保護 (CDP: Continuous Data Protection) CDP is an abbreviation of "Continuous Data Protection". It is also called as a real-time backup, is a system of data storage that backs up data in an organization or enterprise on a sy…

Git實戰(二)原理

上次的博文Git實戰&#xff08;一&#xff09;版本號控制概述中我們簡介了一下版本號控制系統的概念&#xff0c;重點對版本號控制的三種類型進行了分析和對照&#xff0c;從本篇博文開始我們進入Git的世界&#xff0c;首先介紹一下Git實現版本號控制的原理。 Git與SVN等其它版…

什么是html的混雜模式_HTML的完整形式是什么?

什么是html的混雜模式HTML&#xff1a;超文本標記語言 (HTML: Hyper Text Markup Language) HTML is an abbreviation of Hypertext markup language. Hypertext markup language is a text based standard markup language used to create web pages and design documents whi…

PHP-Manual的學習----【語言參考】----【類型】-----【對象】

Object 對象1.對象初始化要創建一個新的對象 object &#xff0c;使用 new 語句實例化一個類&#xff1a; class foo{ function do_foo(){ echo "1111"; }}$bar new foo;echo $bar->do_foo();輸出&#xff1a;1111注解&#xff1a;一個類可以初始化…

kotlin 兩個數字相加_Kotlin程序交換兩個數字

kotlin 兩個數字相加Given two numbers, we have to swap them. 給定兩個數字&#xff0c;我們必須交換它們。 Example: 例&#xff1a; Input:First number: 10Second number: 20Output:First number: 20Second number: 10To swap two numbers – here we are using third v…

Kotlin入門(14)繼承的那些事兒

上一篇文章介紹了類對成員的聲明方式與使用過程&#xff0c;從而初步了解了類的成員及其運用。不過早在《Kotlin入門(12)類的概貌與構造》中&#xff0c;提到MainActivity繼承自AppCompatActivity&#xff0c;而Kotlin對于類繼承的寫法是“class MainActivity : AppCompatActiv…

在Scala中列出| 關于Scala列表的完整教程

Scala | 清單 (Scala | List) List in Scala is a collection that stores data in the form of a liked-list. The list is an immutable collection which means the elements of a list cannot be altered after the list is created. Lists are flexible with data types, …

MySQL單機多實例部署詳解之------多實例分別定義不同的配置文件

mysql多實例安裝---分別定義不同的配置文件1.安裝MySQL需要的依賴包[rootMySQL ~]# yum install ncurses-devel libaio-devel cmake -y[rootMySQL ~]# rpm -qa ncurses-devel libaio-develncurses-devel-5.7-4.20090207.el6.x86_64libaio-devel-0.3.107-10.el6.x86_642.安裝編譯…

javascript模塊_JavaScript中的模塊

javascript模塊JavaScript模塊 (JavaScript Modules) One of the key features of programming fundamentals is breaking down your code into fragments. These fragments depending on its functionality have been coined various terms like functions, components, modul…

在mac上安裝Docker

1.進入一下地址進行下載docker https://download.docker.com/mac/stable/Docker.dmg 進入后進行下載后進行安裝 2.將其拖動到Appliaction中即可 3.第一打開會有一個這樣的歡迎頁面 3.檢查是否安裝完成 出現上圖所示標示安裝完成了

composer 檢查鏡像_檢查N元樹中的鏡像

composer 檢查鏡像Problem statement: 問題陳述&#xff1a; Given two n-ary trees, the task is to check if they are mirrors of each other or not. 給定兩個n元樹&#xff0c;任務是檢查它們是否互為鏡像。 Note: you may assume that root of both the given tree as …

浪潮各機型前面板指示燈含義

NF560D2 NF3020M2 NF5020M3 NF5140M3 NF5212H2 NF5220 NF5224L2 NF5240M3 NF5270M3 NF5280M2 NF5280M3 NF5540M3 NF5580M3 NF8420M3 NF8520 NF8560M2 說明&#xff1a;轉浪潮官網。

python dll 混合_Python | 條線混合圖

python dll 混合In some of the cases, we need to plot a bar-line hybrid plot. This plot helps in a better understanding of dynamics as well as the relative magnitude of each point in the plot. Bar-Line Hybrid Plots are mostly used for the representation of …

測試八 賽后感受

測試八 當我打開T1的時候&#xff0c;就沒有往下看題目了&#xff0c;主要是發現T1就是之前做過&#xff0c;而且我也看過題解的題目&#xff0c;接著就開始鉆研&#xff0c;當然&#xff0c;也沒什么好鉆研的&#xff0c;大概思路還是知道的&#xff0c;再寫寫數據就已經很清晰…

推薦五個免費的網絡安全工具

導讀&#xff1a; 在一個完美的世界里&#xff0c;信息安全從業人員有無限的安全預算去做排除故障和修復安全漏洞的工作。但是&#xff0c;正如你將要學到的那樣&#xff0c;你不需要無限的預算取得到高質量的產品。這里有SearchSecurity.com網站專家Michael Cobb推薦的五個免費…

bios部署模式審核模式_BIOS的完整形式是什么?

bios部署模式審核模式BIOS&#xff1a;基本輸入輸出系統 (BIOS: Basic Input Output System) BIOS is an abbreviation of the Basic Input Output System. In the beginning, when you first set on your computer, the first software which starts run by the computer is &…

day04-裝飾器

一、裝飾器定義 1&#xff09;裝飾器&#xff1a;本質是函數。 2&#xff09;功能&#xff1a;用來裝飾其他函數&#xff0c;顧名思義就是&#xff0c;為其他的函數添加附件功能的。 二、原則 1&#xff09;不能修改被裝飾函數的源代碼 2&#xff09;不能修改被裝飾函數的調用方…

c 語言bool 類型數據_C ++中的bool數據類型

c 語言bool 類型數據In C programming language, to deal with the Boolean values – C added the feature of the bool data type. A bool variable stores either true (1) or false (0) values. 在C 編程語言中&#xff0c;為了處理布爾值– C 添加了bool數據類型的功能 。…

C ++中的std :: binary_search()

binary_search()作為STL函數 (binary_search() as a STL function) Syntax: 句法&#xff1a; bool binary_search (ForwardIterator first, ForwardIterator last, const T& value);Where, 哪里&#xff0c; ForwardIterator first iterator to start of the range For…