读廖雪峰python教程-知识梳理

读廖雪峰python教程

1、四个空格

2、

自己运行的部分代码行

>>> s4=r'''hello,
... lisa!'''
>>> print(s4)
hello,
lisa!
>>>

3、unicode 

ASCII

可变长编码UTF-8

>>> s1=72
>>> s2=85
>>> r=s2/s1
>>> print('xiaomingchengjitishengle%.2f'%(r))
xiaomingchengjitishengle1.18
>>> '中文'.encode('gb2312')
b'\xd6\xd0\xce\xc4'

 4、list

>>> classmates = ['xumin','suman']
>>> classmates
['xumin', 'suman']
>>> s1 = 1
>>> s1
1
>>> len(classmates)
2
>>> classmates90]
  File "<stdin>", line 1
    classmates90]
                ^
SyntaxError: invalid syntax
>>> classmates[0]
'xumin'
>>> classmates[-1]
'suman'
>>> classmates.append('tanfeng')
>>> classmates
['xumin', 'suman', 'tanfeng']
>>> classmates.inset(1,'zhongyichen')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'inset'
>>> classmates.insert(1,'zhongyichen')
>>> classmates
['xumin', 'zhongyichen', 'suman', 'tanfeng']
>>>
>>> classmates.pop()
'tanfeng'
>>> classmates
['xumin', 'zhongyichen', 'suman']
>>> classmates[1] = 'tanfeng'
>>> classmates
['xumin', 'tanfeng', 'suman']
>>>
>>>
>>> list = ['a',123,True]
>>> list
['a', 123, True]
>>> s = ['python','java',['a','php'],'scheme']
>>> len(s)
4
>>> s
['python', 'java', ['a', 'php'], 'scheme']
>>> list = []
>>> len(list)
0
>>> list
[]

5、tuple

元素不可变

6、if语句

>>> age = 20
>>> if age >= 18:
... print('your age is ',age)
  File "<stdin>", line 2
    print('your age is ',age)
        ^
IndentationError: expected an indented block

7、循环

#依次打印姓名

>>> for a in name:
...  print(a)
...
name1
name2
name3
>>> name
['name1', 'name2', 'name3']

#打印奇数

>>> while n <10:
...   n = n+1
...   if n % 2 ==0:
...        continue
...   print(n)
...
1
3
5
7
9

8、dict

类map

>>> d = {'xumin':95,'suman':100}
>>> d
{'xumin': 95, 'suman': 100}
>>> d['xumin']
95
>>> d['tanfeng'] = 99
>>> d['tanfeng']
99
>>> 'tanfeng' in d
True
>>> d.get('xumin')
95
>>> d.get('xuminmin',-1)
-1
>>> d
{'xumin': 95, 'suman': 100, 'tanfeng': 99}
>>> d.pop('suman')
100
>>> d
{'xumin': 95, 'tanfeng': 99}
>>>

key value

9、set

类dict,与list连用

>>> s = set([1,1,2,3,3])
  File "<stdin>", line 1
    s = set([1,1,2,3,3])
           ^
SyntaxError: invalid character in identifier
>>> s = set([1,1,2,3,3])
>>> s
{1, 2, 3}
>>> s.add(4)
>>> s
{1, 2, 3, 4}
>>> s.remove(4)
>>> s
{1, 2, 3}
>>> s1 = set([1,2,3])
>>> s1
{1, 2, 3}
>>> s2 = set([2,3,4])
>>> s1 & s2
{2, 3}
>>> s1 | s2
{1, 2, 3, 4}

10、

 

 

 

ing

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值