#基础入门

day1_1
python学习-(输入、输出、运算符)

1.1

#coding=utf-8

print(“hello oracle”)

a=“oracle”

b=“www.oracle.com”

print(’{0}网址: {1}’.format(a,b))

print(’{}网址: {}’.format(‘甲骨文’,‘www.oracle.com’))

print(’{name}网址: {site}’.format(name=‘甲骨文’,site=‘www.oracle.com’))

python如何将input中数组的值变为int python如何input输入数组_python数据结构


1.2a=9

b=10.5

c=“cylcui”

print(type(a)

python如何将input中数组的值变为int python如何input输入数组_oracle_02


1.3

#算数表达式

a=9

b=8

print(a/b)

print(a%b)

print(a//b)#取整

python如何将input中数组的值变为int python如何input输入数组_python_03


1.4

#逻辑运算符

a=True

b=False

print(a)

print(not a)

print(a or b)

c=6

print(not c)

python如何将input中数组的值变为int python如何input输入数组_python_04


1.5

d=12

e=9

f=(d<e) and d<3

print(f)

print(d)

python如何将input中数组的值变为int python如何input输入数组_字符串_05

day1_2
python学习-(字符串)

2.1

a=“he is a string.who are you”

print(len(a))

#将字符串中的第一个字符变成大写

print(a.capitalize())

#将字符串里的单词提取下来

arr=a.split(" ")#将字符串用一个标识符分隔,返回一个数组

print(arr)

#截取字串,a本身可以看作一个关于文字的数组

print(a[3:5])#冒号本身可以截取字符数组,分别表示开始位置下标和结束位置

print(a[3:])#截取i往后的所有单词

print(a[3:-1])

c=a.replace(‘you’,‘me’)

print©

python如何将input中数组的值变为int python如何input输入数组_oracle_06


2.2

#coding=utf-8

#字符串转为int float

s=‘11’

a=int(s)

b=float(s)

print(a/4)

print(b)

#将数字型转为str

sa=str(a)

print (type (sa))

python如何将input中数组的值变为int python如何input输入数组_元组_07

day1_3
python学习-(list集合)

3.1
#coding=utf-8
‘’'list集合
特点:1.可存储相同的元素
2.可修改、删除元素

‘’’

#定义一个集合

lst=[1]

#往里放入元素

lst[0]=9#访问第一个元素

print(lst)

python如何将input中数组的值变为int python如何input输入数组_元组_08


3.2

lst=[]

lst.append(1)

lst.append(2)

lst.append(3)

print(lst)

python如何将input中数组的值变为int python如何input输入数组_python数据结构_09


3.3

lst=[]

lst.append(1)

lst.append(2)

lst.append(3)

#访问元素 下表从0算起

print(lst[2])

#支持切片访问!!!!重要

print(lst[1:])

#访问前两个元素

print(lst[0:2])

#修改lst某个元素

lst[0]=100

print(lst)

#删除lst某个元素,删除后lst变化

lst.remove(100)

print(lst)

python如何将input中数组的值变为int python如何input输入数组_oracle_10


3.4

lst=[]

lst.append(1)

lst.append(2)

lst.append(3)

#lst集合加入一个集合,二者合并,【2,3】需要跟【4,5,6】

a=[4,5,6]

lst.append(a)

print(lst)

python如何将input中数组的值变为int python如何input输入数组_oracle_11


3.5

lst=[]

lst.append(1)

lst.append(2)

lst.append(3)

#lst集合加入一个集合,二者合并,【2,3】需要跟【4,5,6】

a=[4,5,6]

lst.extend(a)

print(lst)

print(len(lst))#集合长度

python如何将input中数组的值变为int python如何input输入数组_字符串_12


3.6

#多维列表 二维数组是关于一维数组的一维数组

a=[[1,2,3],[4,5,6]] #2*3

#访问元素 第二行第三个

print(a[1][2])

#切片

print(a[0])#获取第一行

print(a[0][:])

#获取第三列 二维数组切片

#print(a[:][2])#所有行的第三列 !暂不支持获取某列

#获取第2行第1、2列

print(a[1][0:2])

python如何将input中数组的值变为int python如何input输入数组_字符串_13

day1_4
python学习-(元组和字典)

4.1
#coding=utf-8
‘’'元组tuple 与列表相似,不同之处在于元组中元素不可以修改!!!

字典 dict

‘’’

t=(1,2,3,4,5)#元组,存5个元素

print(len(t))

print(t[0])

#找出元组最大值、最小值

print(max(t))

print(min(t))

#元组中元素不可以修改!!!

#t[0]=100 错误

#描述坐标系中的几个点(0,0)(1,1) 怎么存储 用集合

lst=[(1,2),[9,5],[10,2]]

#小括号 元组的意思

print(lst[1])

print(lst[1][0])#第二个元组的第一个元素

python如何将input中数组的值变为int python如何input输入数组_python_14


4.2

‘’‘字典结构,存储格式{k1:v1,k2:v2}

例子:{“of”:100,“the”:50,“score”:3}

特点:1.成对出现 有key,跟value

2.字典中不可以出现相同的k

如果出现跟之前相同的key,后出现的将前面的覆盖!!!

3.字典可以修改

‘’’

dic={}#定义一个空字典

#装入元素

dic[“of”]=100

dic[“the”]=50

dic[“score”]=3

print(dic)

python如何将input中数组的值变为int python如何input输入数组_oracle_15


4.3

dic={}#定义一个空字典

#装入元素

dic[“of”]=100

dic[“the”]=50

dic[“score”]=3

dic[“of”]=200

print(dic)

#想改掉某个key对应的value

dic[“the”]=1000

print(dic)

print(dic[“the”])

print(dic.get(“the”))

#删除某个kv

del dic[“the”]

print(dic)

#清空字典

dic.clear()

print(dic)

python如何将input中数组的值变为int python如何input输入数组_元组_16


4.4

dic={“of”:100,“the”:50,“score”:3}#花括号 字典

print(dic)

#获取字典的kv对组成的集合

kv=dic.items()

print(kv)

python如何将input中数组的值变为int python如何input输入数组_python数据结构_17

day1_5
python学习-(条件语句)

5.1

#coding=utf-8

‘’‘if 条件:

执行成立的代码

else:

执行不成立的代码

定义了一个被除数,输入一个除数,最后计算商

‘’’

a=100 #被除数

chushu=input(‘请输入除数’)

#类型转换

chushu=int(chushu)

#计算

shang=a/chushu

print(“商是: %f”%(shang))

python如何将input中数组的值变为int python如何input输入数组_元组_18


5.2

#coding=utf-8

a=100 #被除数

chushu=input(‘请输入除数’)

#类型转换

**chushu=int(chushu)
#加判断,如果除数!=,计算,否则,提示输入不合法
#计算
if chushu==0:
print(“您的输入不合法!”)
else:
shang=a/chushu
print(“商是: %f”%(shang))

python如何将input中数组的值变为int python如何input输入数组_oracle_19


5.3

‘’‘课堂案例:模拟接听电话,根据来电号码选择如何接听

‘’’
 phnotallow=input(“来电了…”)
 phnotallow=int(phone)#获取一个电话号码
 if phone110:
 print(“1”)
 elif phone101:
 print(“2”)
 else:
 print(“正常接听”)

python如何将input中数组的值变为int python如何input输入数组_python数据结构_20


5.4

score=input(“请输入学生的成绩:”)
 score=int(score)
 if score<0 or score>100:
 print(“输入的成绩不合法!”)
 elif score>=0 and score<60:
 print(“不及格”)
 elif score>=60 and score<80:
 print(“及格”)
 else:
 print(“良好”)

python如何将input中数组的值变为int python如何input输入数组_字符串_21