栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python基础(二)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python基础(二)

1.list和tuple共同点和区别 (1)共同点:list和tuple都属于序列; (2)不同点:list可以随时添加和删除其中的元素.(元素可以改变); tuple一旦定义后,tuple中的元素不能再被改变,也不能增删.(元素不能改变) 2.定义一个变量,包含现在所学的数据类型
list_data = [1,1.1,"hello",1+2j,b'123',None,True,(1,2,3),[1,2,3]]
print(list_data)
print(type(list_data))
D:pythonpython.exe D:/python/python_code/var_cod.py
[1, 1.1, 'hello', (1+2j), b'123', None, True, (1, 2, 3), [1, 2, 3]]


Process finished with exit code 0
3.目前学到的序列有哪些?
   将除tuple之外的序列转换为tuple
   将除list之外的序列转换为list (1)字符串 字节 tuple list (2)  将除tuple之外的序列转换为tuple
str_data = 'hello'
byt_data = b'123'
list_data = [1,2,3]
tuple_data1 = tuple(str_data)
tuple_data2 = tuple(byt_data)
tuple_data3 = tuple(list_data)
print(tuple_data1)
print(tuple_data2)
print(tuple_data3)
D:pythonpython.exe D:/python/python_code/var_cod.py
('h', 'e', 'l', 'l', 'o')
(49, 50, 51)
(1, 2, 3)

Process finished with exit code 0
 将除list之外的序列转换为list
str_data = 'hello'
byt_data = b'123'
tuple_data = (1,2,3)
list_data1 = list(str_data)
list_data2 = list(byt_data)
list_data3 = list(tuple_data)
print(list_data1)
print(list_data2)
print(list_data3)
D:pythonpython.exe D:/python/python_code/var_cod.py
['h', 'e', 'l', 'l', 'o']
[49, 50, 51]
[1, 2, 3]

Process finished with exit code 0
4.tuple中有哪些操作方法
 def count(self, *args, **kwargs): # real signature unknown
        """ Return number of occurrences of value. """
        pass

    def index(self, *args, **kwargs): # real signature unknown
        """
        Return first index of value.
        
        Raises ValueError if the value is not present.
        """
        pass
5.list中有哪些操作方法
class list(object):
    """
    Built-in mutable sequence.
    
    If no argument is given, the constructor creates a new empty list.
    The argument must be an iterable if specified.
    """
    def append(self, *args, **kwargs): # real signature unknown
        """ Append object to the end of the list. """
        pass

    def clear(self, *args, **kwargs): # real signature unknown
        """ Remove all items from list. """
        pass

    def copy(self, *args, **kwargs): # real signature unknown
        """ Return a shallow copy of the list. """
        pass

    def count(self, *args, **kwargs): # real signature unknown
        """ Return number of occurrences of value. """
        pass

    def extend(self, *args, **kwargs): # real signature unknown
        """ Extend list by appending elements from the iterable. """
        pass

    def index(self, *args, **kwargs): # real signature unknown
        """
        Return first index of value.
        
        Raises ValueError if the value is not present.
        """
        pass

    def insert(self, *args, **kwargs): # real signature unknown
        """ Insert object before index. """
        pass

    def pop(self, *args, **kwargs): # real signature unknown
        """
        Remove and return item at index (default last).
        
        Raises IndexError if list is empty or index is out of range.
        """
        pass

    def remove(self, *args, **kwargs): # real signature unknown
        """
        Remove first occurrence of value.
        
        Raises ValueError if the value is not present.
        """
        pass

    def reverse(self, *args, **kwargs): # real signature unknown
        """ Reverse *IN PLACE*. """
        pass

    def sort(self, *args, **kwargs): # real signature unknown
        """
        Sort the list in ascending order and return None.
        
        The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
        order of two equal elements is maintained).
        
        If a key function is given, apply it once to each list item and sort them,
        ascending or descending, according to their function values.
        
        The reverse flag can be set to sort in descending order.
        """
        pass

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/942273.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号