Python3基础 list len 输出元素的个数

?

  • python : 3.7.0
  • OS : Ubuntu 18.04.1 LTS
  • IDE : PyCharm 2018.2.4
  • conda : 4.5.11
  • type setting : Markdown

?

code

[email protected]:~$ source activate py37
(py37) [email protected]:~$ ipython
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
Type ‘copyright‘, ‘credits‘ or ‘license‘ for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type ‘?‘ for help.

In [1]: empty_list = []

In [2]: len(empty_list)
Out[2]: 0

In [3]: empty_list.append(1)

In [4]: len(empty_list)
Out[4]: 1

In [5]: empty_list.append([1, 2])  # 列表中的列表算 单个元素

In [6]: empty_list
Out[6]: [1, [1, 2]]

In [7]: len(empty_list)
Out[7]: 2

In [8]: exit
(py37) [email protected]:~$ source deactivate py37
[email protected]:~$

?

resource

  • [文档] https://docs.python.org/3/
  • [规范] https://www.python.org/dev/peps/pep-0008/
  • [规范] https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/
  • [源码] https://www.python.org/downloads/source/
  • [ PEP ] https://www.python.org/dev/peps/
  • [平台] https://www.cnblogs.com/

?



Python具有开源、跨平台、解释型、交互式等特性,值得学习。

Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。

代码的书写要遵守规范,这样有助于沟通和理解。

每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

原文地址:https://www.cnblogs.com/xingchuxin/p/9696494.html

时间: 2024-08-01 23:29:56

Python3基础 list len 输出元素的个数的相关文章

Python3基础 count 返回指定元素在列表中的个数

镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1 code 1 aList=[1,2,3,1,2,3,[1,2,3]] 2 res=aList.count(1) 3 print(res) 2 show ------------------------------------------博文的精髓,在技术部分,更在镇场一诗.Python是优秀的

Python3基础 str 循环输出list中每个单词及其长度

? python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 conda : 4.5.11 type setting : Markdown ? code """ @Author : 行初心 @Date : 18-9-23 @Blog : www.cnblogs.com/xingchuxin @GitHub : github.com/GratefulHeartCoder """ de

python3基础:格式化输出

直接简单的输出#简单输出一个字符串 >>>print('hello python apple') hello python apple #简单输出多个字符串 >>>print('hello','python', 'apple') hello python apple #简单输出拼接字符串>>>print('hello'+ '\tpython'+ '\tapple') hello python apple 格式化输出 --为了让输出更加美观主要是 1.%

Python3基础 index 返回一个元素在列表中第一次出现的索引值

镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1 code 1 aList=[1,2,3,1,2,3,[1,2,3]] 2 res=aList.index(1) 3 print(res) 2 show ------------------------------------------博文的精髓,在技术部分,更在镇场一诗.Python是优秀的

Python3基础 print(,end=) 输出内容的末尾加入空格

镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.------------------------------------------ code: word='helloworld' for character in word: print(character,end=' ') #每个字母后加上一个空格 result: ============= RESTART: C:/Users/Administrator/Deskto

Python3基础 str for 输出字符串中的每个字符

? python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 conda : 4.5.11 type setting : Markdown ? code """ @Author : 行初心 @Date : 18-9-23 @Blog : www.cnblogs.com/xingchuxin @GitHub : github.com/GratefulHeartCoder """ de

Python3基础 print %d 输出整数

? ???????Python : 3.7.0 ?????????OS : Ubuntu 18.04.1 LTS ????????IDE : PyCharm 2018.2.4 ??????Conda : 4.5.11 ???typesetting : Markdown ? code coder@Ubuntu:~$ source activate py37 (py37) coder@Ubuntu:~$ ipython Python 3.7.0 (default, Jun 28 2018, 13:1

Python3基础 tuple 通过拆分元素 把元组的数据删除

? ???????Python : 3.7.0 ?????????OS : Ubuntu 18.04.1 LTS ????????IDE : PyCharm 2018.2.4 ??????Conda : 4.5.11 ???typesetting : Markdown ? code """ @Author : 行初心 @Date : 18-9-23 @Blog : www.cnblogs.com/xingchuxin @Gitee : gitee.com/zhichengji

HLG 1710 给出三个集合a,b,c,统计集合a元素+集合b中元素=集合c中的元素的个数 (基础题)

链接: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1710 Description 有A. B. C 三个集合的,其中a∈A, b ∈ B, c ∈ C,求有多少种方式使得a + b = c. Input 有多组测试数据,请处理到文件结束. 对于每组测试数据,有三行: 第一行为A集合的描述,第一个数为n,表示A集合有n个数,接下来有n个整数a1~an. 第二行为B集合,第三行为C集合,表