python type函数
生活随笔
收集整理的這篇文章主要介紹了
python type函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
阿里云大學人工智能學前小測驗-Python測試
4.代碼 print(type([1,2])) 輸出結果為
A. <class 'list'>
B. <class 'tuple'>
C. <class 'int'>
D. <class 'set'>
?
如何知道一個變量的數據類型
基本上入門級最開始使用的就是type 函數,如:
?
1 num1 = 1232 str1 = 'hello'3 noneobj = None4 print(type(num1))5 print(type(str1))6 print(type(noneobj))7 8 <class 'int'>9 <class 'str'> 10 <class 'NoneType'>直接對數據對象本身進行type ,如type(123),type('hello'),type(None),結果是一樣的。
對于一些內置變量,比如abs 函數,max 函數, len 函數,也都可以使用type 去獲取他們的對象類型。
1 print(type(abs)) 2 print(type(max)) 3 print(type(len)) 4 5 <class 'builtin_function_or_method'> # 這一類說明是Python 內置的函數 6 <class 'builtin_function_or_method'> 7 <class 'builtin_function_or_method'>補充:python數據類型
? ? ? ? ? ? ?字符串 str string “”或 ‘’
????????????? 列表 list []
????????????? 元祖 tuple () 類似于列表,但不能修改元素
????????????? 字典 dict dictionary {} 鍵值對
????????????? 集合 set {} 非鍵值對
? ? ? ? ? ? ? 集合(set)是一個無序的不重復元素序列。可以使用大括號 { } 或者 set() 函數創建集合,注意:創建一個空集合必須用 set() 而不是 { },因為 { } 是用來創建一個空字典。
總結
以上是生活随笔為你收集整理的python type函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python数据类型转换方法列表
- 下一篇: python 重复输出字符串