Day 03

'''
1. 什么是数据类型
变量值即我们存放的数据,数据类型及变量值的类型

2. 变量值为何要区分类型
因为变量值使用记录现实世界中事物的特征,针对不同的特征就应该用不同类型的值去标识

3. 如何应用数据类型
'''

# 一 数字类型:
# 1. 整型int: 年龄\身份证号\电话号码\等级
# age=18 # age=int(18)
# print(id(age),type(age),age)

# 2. 浮点型float:薪资\身高\体重
# salary=3.1 #salary=float(3.1)
# print(id(salary),type(salary),salary)

# 二 字符串类型str: 名字\家庭住址\单个爱好\性别等等描述性质的特征
# 定义:在引号(单引号\双引号\三引号)内包含一串字符
# name1='egon'
# name2="egon"
# name3="""egon"""
# print(type(name1))
# print(type(name2))
# print(type(name3))
# msg='my name is "egon"'
# print(msg)

msg1='hello'
msg2='world'
# res=msg1 + msg2
# print(res,type(res))
# print(msg1)
# print('='*100)
# print(msg2)

# 三 列表list: 记录多个值,比如人的多个爱好,一个班级多个学生的性别
#定义:在[]内用逗号分隔开多个任意类型的值
l=[1,3.1,'aa',['a','b','c',['aaaa','bbbb']]]
# print(l)
# print(l[0])
# print(l[2])
# print(l[3][1])
# print(l[3][3][0])


# 四 字典dict: 记录多个key:value值,
# 引子:
# students=['egon','lxx','yxx']
# print(students[0])

# name age sex level hobbies
# info=['egon',18,'male',10,['music','read','dancing']]
# print(info[0])
# print(info[2])

# 定义:在{}内用逗号分隔开多个key:value的值,其中value可以是任意数据类型,
# 而key通常应该是字符串类型
info={
'name':'egon',
'age':18,
'sex':'male',
'level':10,
'hobbies':['music','read','dancing']
} #info=dict(...)
# print(type(info))
# print(info['level'])
# print(info['age'])
# print(info['hobbies'][1])

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



# 五: 布尔类型bool: True/False,用来标识条件是否成立
# age=18
#
# print(age > 30)
# print(age < 30)

# 所有类型的值都自带布尔值: 当数据类型的值为0,None,空时,布尔值为False,除此以外都为True
# print(bool(0))
# print(bool(None))
# print(bool(''))
# print(bool([]))
# print(bool({}))
# print(bool(1))

if None:
print('条件成立了11确实大于10的')
#一 变量值具备三个特征:
# 1. id: 变量值的唯一编号,内存地址不同id则不同
# 2. type:类型
# 3. value

# name='egon'
# print(id(name))
# age=18
# print(id(age))

# x=10
# y=x
# print(id(x),id(y))

# age=10
# print(id(age))
# print(type(age))
# print(age)


#二: is与==
#is身份运算:比较的是id是否相等
#==判断值是否相等

x=10
y=x
print(id(x),id(y))
print(x is y) #id相等,值一定相等
print(x == y)


'''
值相等id不一定相等
>>> x=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
>>> y=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
>>> id(x)
2181129522824
>>> id(y)
2181129523040
>>> x is y
False
>>> x == y
True
'''

# x=100000000000000000000000000000000000000
# y=100000000000000000000000000000000000000
print(x is y)


# 三 常量
OLDBOY_OF_AGE=73
OLDBOY_OF_AGE=74
print(OLDBOY_OF_AGE)
# 在python3中的input会将用户输入的任何内容都存成str类型
# name=input("请输入您的用户名: ") #name="egon"
# pwd=input("请输入您的密码: ") #pwd='123'

# if name == 'egon' and pwd == '123':
# print('登陆成功')
# else:
# print('用户名或者密码输错了傻叉')

# 了解:
# 在python3中只有一个input,而python2中有input和raw_input
# 1.其中python2的raw_input与python3的input是一样
# 2 不一样的是:python2的input要求使用者必须输入一个明确的数据类型,输入什么类型就存成什么类型
# age=input('>>>: ') #age="18"
# print(age,type(age))
# age=int(age) #age=int("18") #age=18
# print(age > 30)

# name=input('请输入您的用户名: ')
# age=input('请输入您的年龄: ')

# print('my name is my age is ',name,age)
# print('my name is ',name,'my age is ',age)

# print('my name is %s my age is %s' %(name,age))
# print('my name is %s my age is %s' %([1,2,3],18)) #%s可以收任意类型的值
# print('my name is %s my age is %d' %('egon',18))
# print('my name is %s my age is %d' %('egon','18')) #%d只能接收整型






转载于:https://www.cnblogs.com/djwcz/p/10196753.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值