一:python编程核心知识点

1、交互模式和文件模式

2、变量类型、输入和输出

整数、小数、字符串、复数、列表、元组、字典、集合

int、float、str、complex、list、tuple、dict、set

>>> a=3
>>> type(a)
<class 'int'>
>>> b=1.0
>>> type(b)
<class 'float'>
>>> s='abc'
>>> type(s)
<class 'str'>
>>> d=1+2j
>>> type(d)
<class 'complex'>
>>> l=[1,2,'a']
>>> type(l)
<class 'list'>
>>> t=(1,2,3)
>>> type(t)
<class 'tuple'>
>>> t=(a,b,c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'c' is not defined
>>> type(t)
<class 'tuple'>
>>> t=('a','b','c')
>>> type(t)
<class 'tuple'>
>>> dt={'a':1,'b':c}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'c' is not defined
>>> dt={'a':1,'b':'c'}
>>> type(dt)
<class 'dict'>
>>> s=set([1,2,3])
>>> type(s)
<class 'set'>

>>> content = input("请输入你的年龄:")     #不管输入的是什么内容,都是存储为str类型
请输入你的年龄:5
>>> print(content)
5

>>> type(content)
<class 'str'>

3、isinstance、类型转换

>>> s=set("123456")
>>> type(s)
<class 'set'>
>>> isinstance(s,int)
False
>>> isinstance(s,set)
True
>>> isinstance(s,float)
False

整数--->小数

整数--->字符串

小数--->整数

小数--->字符串

字符串--->整数

整数--->小数

>>> float(1)
1.0
>>> str(1)
'1'
>>> int(1.1)
1
>>> str(1.1)
'1.1'
>>> int('123')
123
>>> float(''123)
  File "<stdin>", line 1
    float(''123)
              ^
SyntaxError: invalid syntax
>>> float('123')
123.0

4、if elif else

练习题:做一个判断,输入一门成绩,如果90分以上就是优秀。80到90之间良好,80以下为一般

>>> content=input("请输入你的成绩:")
请输入你的成绩:88
>>> if int(content)>=90:      #行业标准:缩进默认4个空格
...     print('优秀')
... elif 90>int(content)>=80:
...     print("良好")
... else:
...     print("一般")
...
良好
>>> content=input("请输入你的成绩:")
请输入你的成绩:99
>>> if int(content)>=90:
...     print('优秀')
... elif 90>int(content)>=80:
...     print("良好")
... else:
...     print("一般")
...
优秀
>>> content=input("请输入你的成绩:")
请输入你的成绩:0
>>> if int(content)>=90:
...     print('优秀')
... elif 90>int(content)>=80:
...     print("良好")
... else:
...     print("一般")
...
一般

5、for 和 while

遍历思想: for 和 wihle

>>> for a in range(10):
...     print(a)
...
0
1
2
3
4
5
6
7
8
9
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> tuple(range(10))
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

>>> i=0
>>> while i<=9:
...     print(i)
...     i=i+1
...
0
1
2
3
4
5
6
7
8
9

6、单一布尔值什么时候是false?

0、' ' 、[ ] 、() 、{ } 、''' ''' 、 """ """

>>> bool(0)
False
>>> bool('')
False
>>> bool('''''')
False
>>> bool("""""")
False
>>> bool([])
False
>>> bool(())
False
>>> bool({})
False

其他一般都是True

2>1 True

2>3 False

7、练习题:用遍历法,计算出a="123abc"中有几个数字

a="123098ab6383cc"
result=0
for i in a:
    if i in "1234567890":
        result+=1

print(result)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值