一.Introduction

1.8.1 Built-in Atomic Data Types

Python has two main built-in numeric classes(内置函数,int 和 float) that implement the integer and floating point data types。

other operation are  remainder operator %(取模运算),the operator ** is exponentiation(指数运算)

python 中的变量 variable 不像C++、java一样,同一个类型的variable能够refer to many different types of data

1.8.2. Built-in Collection Data Types:

Lists, strings, and tuples (tuples 元组)are ordered collections that are very similar in general structure but have specific differences 。

Sets and dictionaries are unordered collections.

类表,字符串和元组是有序的集合,Sets和字典无序集合

1.list,List中object不需要全部相同类型

.

>>> [1,3,True,6.5]
[1, 3, True, 6.5]
>>> myList = [1,3,True,6.5]
>>> myList
[1, 3, True, 6.5]

,

>>> myList = [0] * 6
>>> myList
[0, 0, 0, 0, 0, 0]

list 列表[1,2,3]*3,说的是将此[1,2,3]重新复制3片,与numpy中array,中* 针对数组中每个元素乘以其常数K

import numpy
>>> myList=[1,2,3]
>>> myList *3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> myarray=numpy.array(myList)
>>> myarray
array([1, 2, 3])
>>> myarray*3
array([3, 6, 9])

List列表的操作特性,List 可以进行pop和insert,pop 弹出的是list中最末尾的元素.

remove 操作可以直接删除list中某个值。()__add__(),called it add method,标识符

2.string:

>>> "David"
‘David‘
>>> myName = "David"
>>> myName[3]
‘i‘
>>> myName*2
‘DavidDavid‘
>>> len(myName)
5
>>>

A major difference between lists and strings is that lists can be modified while strings cannot

list 与string最大不同的点在于List中元素能够进修改,string不能

 3.Tuple ,元组中数据不能被修改的  The difference is that a tuple is immutable, like a string

myTuple=(1,True,4.98)

>>> myTuple
(1, True, 4.98)
>>> myTuple*3
(1, True, 4.98, 1, True, 4.98, 1, True, 4.98)
>>> myTuple[1]=9

Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
myTuple[1]=9
TypeError: ‘tuple‘ object does not support item assignment
>>>

4.Set集合,集合中元素不会有重复的

1.set 中元素显示不会按照一定的顺序,会一种unordered方式:

{3,6,"cat",4.5,False}
{False, 4.5, 3, 6, ‘cat‘}
>>> mySet = {3,6,"cat",4.5,False}
>>> mySet
{False, 4.5, 3, 6, ‘cat‘}
>>>

mylist=[1,2,3,1]

>>> set(mylist)
set([1, 2, 3])

intersection从两个set选择相同的元素setA.intersection(setB)

5.词典:dict.items():得到字典中的每一个类型的元素,dict.get(k,0),从词典中有k得到k,没有的话返回成0

时间: 2024-10-25 20:13:35

一.Introduction的相关文章

Spring AOP之Introduction(@DeclareParents)简介

Spring的文档上对Introduction这个概念和相关的注解@DeclareParents作了如下介绍: Introductions (known as inter-type declarations in AspectJ) enable an aspect to declare that advised objects implement a given interface, and to provide an implementation of that interface on be

Introduction and Basic concepts

1 Network Edge The device such as computers and mobiles connect to the Internet. So they are referred as end systems(who run the application programs) sitting at the edge of the Internet. And we use host and end system interchangeably, that is host=e

Introduction to Machine Learning

Chapter 1 Introduction 1.1 What Is Machine Learning? To solve a problem on a computer, we need an algorithm. An algorithm is a sequence of instructions that should be carried out to transform the input to output. For example, one can devise an algori

The basic introduction to MIX language and machine

reference: The MIX Computer, The MIX Introduction sets, The basic info storage unit in MIX computer is the byte, which stores positive values in the range of 0 to 63. In MIX, Byte only has 6 bytes, and the word Byte refer to MIX 6-byte. A MIX word is

PyQt5 Introduction and components

在开始写代码以前,对PyQt5整体大致了解一下还是有必要的.这方面的东西看看PyQt5官方给出的文档就好,下面就是我从文中截取的部分内容: Introduction PyQt5 is a set of Python bindings for v5 of the Qt application framework from The Qt Company. Qt is a set of C++ libraries and development tools that includes platform

[stm32参考手册] 1、Introduction

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xxand STM32F107xx advanced ARM-based 32-bit MCUs 本资料覆盖范围: 这本资料提供完整的关于上述系列STM单片机的存储器和外设的使用方法.在整个文档中(除非特别说明)是把这几类单片机归于STM32F10XXX系列的. 注:STM32F10XXX是一个包含的各种不同存储器尺寸,不同封装和不同外设的微处理器家族. 其他相关资料引导: 关于订货编号.电气和物理性

〈Effective C++〉读书笔记--Introduction

Introduction 1.Learning the fundamentals of a programming language is one thing; learning how to design and implement effective programs in that language is something else entirely. 想起<重构>里面说的一句话,写出计算机能理解的代码很容易,但是写好人能理解的代码不容易 2.A declaration tells c

[转]A plain english introduction to cap theorem

Kaushik Sathupadi Programmer. Creator. Co-Founder. Dad. See all my projects and blogs → A plain english introduction to CAP Theorem You’ll often hear about the CAP theorem which specifies some kind of an upper limit when designing distributed systems

和Keyle一起学StrangeIoc &ndash; Introduction

Strange: the IoC framework for Unity Strange attractors create predictable patterns, often in chaotic systems. 在混乱的系统中创造出一个可以预测的模式 . Introduction StrangeIoc主要用于C#与Unity3d,我们已经在IOS,Web,Android项目中成功运用,他包含了如下功能,其中大部分功能都是可选的 Strange is a super-lightweigh

A.Kaw矩阵代数初步 学习笔记: 1. Introduction

“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. 第1章课程讲义下载(PDF) Summary Matrix A matrix is a rectangular array of elements. Matrix $A$ is denoted by $$A = \begin{bmatrix}a_{11} & \cdots & a_{1n}\\ \vdots&