There are eight key elements of python

1. data type

2. variant

grammer: objectReference = value

‘=‘  means bind a variant with object in memory.

variant name is case sensitive in pyhon.

3. combination data type

major types are meta and list

meta is fixed.

list is changable.

#x.append(xxx)  == list.append(x,‘xxx‘)

There are two call methods in python. as following.

functionName(arguments)

objectName.methodName(arguments)

4. logical operator

sometimes "is" will give you a different result. in fact. its compared with memory object.

0<=a<=10 equal a>=0 and a<=10

"in" is better used in dict

5. control

a.
    if boolean_expression1:

suite1

elif boolean_expression2:

....

else:

else_suite

b.

while boolean_expression:

suite

c.

for variable in iterable:

suite

6. mathmatic

list must use iterable object.

e.g. seeds+=5 # will get error

seeds+=[5] #correct

7. IO

try:

...

except ValueError as err:

print(err)

continue

except EOFError:

break

8. function

def functionName(argument1,a2,a3...):

suite

时间: 2024-12-22 12:28:43

There are eight key elements of python的相关文章

347. Top K Frequent Elements [medium] (Python)

题目链接 https://leetcode.com/problems/top-k-frequent-elements/ 题目原文 Given a non-empty array of integers, return the k most frequent elements. For example, Given [1,1,1,2,2,3] and k = 2, return [1,2]. Note: You may assume k is always valid, 1 ≤ k ≤ numbe

203. Remove Linked List Elements [easy] (Python)

题目链接 https://leetcode.com/problems/remove-linked-list-elements/ 题目原文 Remove all elements from a linked list of integers that have value val. Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –>

Python中Collections模块的Counter容器类使用教程

1.collections模块 collections模块自Python 2.4版本开始被引入,包含了dict.set.list.tuple以外的一些特殊的容器类型,分别是: OrderedDict类:排序字典,是字典的子类.引入自2.7.namedtuple()函数:命名元组,是一个工厂函数.引入自2.6.Counter类:为hashable对象计数,是字典的子类.引入自2.7.deque:双向队列.引入自2.4.defaultdict:使用工厂函数创建字典,使不用考虑缺失的字典键.引入自2.

07 映射和集合类型 - 《Python 核心编程》

?? 映射类型: 字典 ?? 操作符 ?? 内建函数 ?? 内建方法 ?? 字典的键 ?? 集合类型 ?? 操作符 ?? 内建函数 ?? 内建方法 ?? 相关模块 7.1 映射类型:字典 字典是Python 语言中唯一的映射类型. 映射类型对象里哈希值(键) 和指向的对象(值)是一对多的关系. 字典类型和序列类型容器类(列表.元组)的区别是存储和访问数据的方式不同. 序列类型只 用数字类型的键(从序列的开始起按数值顺序索引). 映射类型可以用其他对象类型做键:一般最常 见的是用字符串做键(key

Python基本数据类型(一)

目录: 1.运算符 2.type().dir().help()函数 3.基本数据类型常用功能之int.str操作. 正文: 一.运算符 算术运算:  比较运算: 赋值运算:  布尔操作符(逻辑运算):  成员运算: 二.type().dir().help()函数 1.type()函数用来判断数据类型 >>> type(123) <class 'int'> >>> type(123.0) <class 'float'> >>> t

2015/9/4 Python基础(8):映射和集合类型

Python里唯一的映射类型是字典.映射类型对象里,hash值(key)和指向的对象(值)是一对多的关系.字典对象是可变的,这一点上很像列表,它也可以存储任意个数任意类型的Python对象,其中包括容器类型.字典类型和序列类型的区别是存储和访问数据的方式不同.序列类型只用数字类型的键(从序列开始按数值顺序索引.)映射类型的键(key)可以是其他的对象类型(一般是字符串),映射类型的键直接或间接地和存储的数据值相关联.而在映射类型中,数据是无序排列的. 一个字典条目的语法格式是 键:值. 多条字典

Python数据结构

1. 元组(tuple) 元组由不同的元素组成,每个元素可以储存不同类型的数据,如字符串.数字甚至元组.元组是写保护的,即元组创建后不能再做任何修改操作. 1.1 元组的创建 Tuple(元组)由一系列元素组成,所有元素被包含在一对圆括号中.创建元组时可以不指定元素个数,但一旦创建后就不能修改长度 元组的创建格式如下:tuple_name = (元素1,元素2,-) 如果创建空元组,只需要一对空的圆括号:tuple_name = () 如果创建的元组只包含一个元素,应在元素后面加上逗号,以区分元

2.python基础之—列表,元组,字典,集合,字符串的使用方法

一.关于python序列的简介. python里面的序列大部分都可以执行,索引,切片,加,乘,检查长度,以及检查某个成员是否存在,甚至还可以找出这个序列中最小的元素和最大的元素,并且序列都是可迭代的. 解释下个人理解的迭代,迭代(iteration),序列中的迭代就是对序列中的每个元素重复执行某些操作/ 具体的迭代方式后面会说到. 下面就说说python序列的共有特点. 1.索引 一个序列中,所有的元素都有自己的编号,这个编号是从0开始的,这个编号就是所谓的索引,这些元素可以通过索引来依次访问.

Python内置函数(20)——exec

英文文档: exec(object[, globals[, locals]]) This function supports dynamic execution of Python code. object must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a