Python简介/Introduction to Python

1python基础知识

1.1data type:

float - real number
int - integer number
str - string,text
bool - True,False
int, or integer: a number without a fractional part. savings, with the value 100, is an example of an integer.
float, or floating point: a number that has both an integer and fractional part, separated by a point. growth_multiplier, with the value 1.1, is an example of a float.
str, or string: a type to represent text. You can use single or double quotes to build a string.
bool, or boolean: a type to represent logical values. Can only be True or False (the capitalization is important!).
type(a) # 得类型

1.2different type = different behavior : +

2 + 3 -> 5
‘type’ + ‘tyep’ -> ‘typetype’
字符串不能和数值变量混合计算

1.3type conversion类型转变

int() float() str() bool()

variable assignment 变量分配: x = 5
access information 获取信息
syntax 语法

2Python list

  • name a collection集合 of values
  • contain any type
  • contain different type :
    fam =['liz', 1.2, 'hong', 3.2, 'zhang', 4]
    fam2 = [ ['liz', 1.2], ['hong', 3.2], ['zhang', 4] ] # a list of lists
2.1子集列表列表索引
2.2list slicing

在这里插入图片描述在这里插入图片描述

2.3subsetting lists of lists
x = [["a", "b", "c"],
     ["d", "e", "f"],
     ["g", "h", "i"]]
x[2][0]
x[2][:2]
x[:2][2]  #为何不行
2.4manipu lating lists 操作列表

AAAAA

x = ['a','b','c']
y = x 
y[1] = 'z'
y #  y 为 ['a','z','c']
x #  x 为 ['a','z','c']

BBBBB

x = ['a','b','c']
y = x[:]  # 或者 y = list(x)
y[1] = 'z'
y #  y 为 ['a','z','c']
x #  x 为 ['a','b,'c']  没有变
# x[:] or list[x] 防止y的修改影响x

列表操作

    #change list of elements
    x = ["a", "b", "c", "d"]
    x[1] = "r"
    x[2:] = ["s", "t"]
    #extend a list  + delete list elements 
    x = ["a", "b", "c", "d"]
    y = x + ["e", "f"]
    z = x
    del(x[1])  #  x = ["a", "c", "d"]   y = ["a", "b", "c", "d","e", "f"]  z = ["a", "c", "d"]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值