观第8期day03笔记有感(顺便测试markdown特性)

读 第8期上课笔记有感

整形

num = 10000
print(num,id(num),type(num)) #10000 1987434605392 <class 'int'>
print(num - 1) #9999

浮点型

alary = 8888.01234567890
salary2 = 8888.1987
print(salary)#8888.0123456789
print('%.6f' % salary) #8888.012346
# # %f对浮点型数据进行占位
# # .后的数据数字表示小数精度
print('%015.6f' % salary2) ##00008888.198700
#15 表示 加上标点符号 一共15 位 0 表示 不足15位的用0
#6表示小数点后精确到6位
print('%-022.13f' % salary2) #8888.1987000000008    ]还有4个空格
# -表示 左对齐 22表示一共有22位
#13表示精确到小数点后13位
#但是13+1+4=18 不够22位 所以后面有4个空格
INFO = '%-022.13f' % salary2
print(INFO)
##可以用变量或者常量存这个格式化过的数据

bool类型

#bool类型就是两个值 Trule 和 False
result = False
print(result) #False

str类型 : '' | "" |"""""" |''''''

height = '180cm'
print(height) #180cm
print(height,type(height)) #180cm <class 'str'>

height="""180cm"""
print(height,type(height)) #180cm <class 'str'>

code='''
段落
段落
'''
print(code,type(code)) #输出内容
#
#段落
#段落
# <class 'str'>

输入数据

name = input('name1: ')
age = input("age: ")
print('姓名 '+name+',年龄 '+age) #姓名 2,年龄3
#_________________________________________
# # %s是万能占位符,
# %是用来连接有占位符的字符串与需要占位的变量,多个变量用()包裹
#继续用之前获得的name 和 age
get_info = """
--------------- 测试百分号s
姓名 : %s 
年龄 : %s
--------------- 测试结束
""" % (name ,age)
print(get_info)

list类型

# # 1.是一个可以存放多个值的容器
# # 2.列表有编号,从0开始标号,对应数据是从左往右 => 列表名[索引]
list1= [1,3,4,5,1]
num2 = 1
print (list1) #[1, 3, 4, 5, 1]
print(id(list1[0])) #1458073056

嵌套

ls = [[1,2,3],[2,3,4],[3,4,[5]]]
# 获取指定的值
get_v1 = ls[0]
get_v2 = ls[1]
get_v3 = ls[2]
get_v3_1 = get_v3[2]
print(get_v1) #[1, 2, 3]
print(get_v2)#[2, 3, 4]
print(get_v3)#[3, 4, [5]]
print(get_v3_1,type(get_v3_1)) #[5] <class 'list'>
print(get_v1[0],type(get_v1[0])) #1 <class 'int'>
print(ls[2][2],type(ls[2][2])) #[5] <class 'list'>
#ls[2][2] 是 [3,4,[5]]]里的[5],所以是list类型
print(ls[2][1],type(ls[2][1])) #4 <class 'int'>

字典

列表能存放多个值,但多个值只能通过index区分,但是index没有语义

需找即可以存放多个值,切每个值有一个语义描述 => dict类型

定义:{}是用来定义字典的语法,key是用来描述最终要访问的value值的,key对于开发者来说是已知的

访问:通过 dic[key]来访问key描述的值

people = {
    'name':'hello',
    'age':'132',
    'gender':'man'
}
print(people) #{'name': 'hello', 'age': '132', 'gender': 'man'}
print(type(people)) #<class 'dict'>
print(people['name']) #hello

字典嵌套列表

dict1 = {
    'name':'egon',
    'hobbies':['play','sleep'],
    'company_info':{
        'name':'oldboy',
        'type':'education',
        'emp_num':'40',
    }
}
print(dict1['name']) #egon
print(dict1['company_info']['emp_num']) #40

例子

students = [
    {'name':'alex','age':'38','hobbies':[
        'play','sleep'
    ],},
    {'name':'egon','age':'18','hobbies':[
        'read','sleep'
    ],},
    {'name':'me!','age':'333','hobbies':[
        'eat','sleep'
    ],},
]
gs = students[1]
print("name is %s,age %s ,hobbies %s"
      %(gs['name'],
        gs['age'],
        gs['hobbies'][1]+' and '+gs['hobbies'][0]))
#name is egon,age 18 ,hobbies sleep and read
总结

python是一个对格式非常执着的语言,

编写者是个强迫症没错了

8期学院一天学完这些 真肝...

猜你喜欢

转载自www.cnblogs.com/blog5434/p/10883635.html
今日推荐