程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python -- similarities and differences among various data types

編輯:Python

character string , list , Tuples , Mutual transformation and difference between sets .

str1 = 'helloworld'
print(str1)
# String to list ,list()
list1 = list(str1)
print(list1)
# String to tuple ,tuple()
tup = tuple(str1)
print(tup)
# List tuple 
tup1 = tuple(list1)
print(tup1)
# String conversion ,set()
set1 = set(str1)
print(set1)# There are no duplicate elements in the set 
# List to set 
set2 = set(list1)
print(set2)
# Tuple to set 
set3 = set(tup)
print(set3)
helloworld
['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']
('h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd')
('h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd')
{
'd', 'o', 'e', 'h', 'r', 'l', 'w'}
{
'd', 'o', 'e', 'h', 'r', 'l', 'w'}
{
'd', 'o', 'e', 'h', 'r', 'l', 'w'}
 Data type comparison character string list Tuples Dictionaries aggregate
Is it orderly yes yes yes no no
Modifiable or not no yes No yes yes

Variable type and immutable type
Variable type , Values can change :

  1. list list
  2. Dictionaries dict
  3. aggregate set

Immutable type , Value cannot be changed :

  1. value type int, long(Python3 Remove ), bool, float
  2. character string str
  3. Tuples tuple

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved