【python】Python的基本数据类型之数字类型与字符串类型

1. Python的基本数据类型

1.1 数字类型

整型(关键字int)      由0~9组成的所有数字,例如:年龄、存款、尺寸、手机号等。
浮点型(关键字float)  包含有小数点,例如:价格,重量
布尔型(关键字bool)   生活通过某种判断得到的真(True)、假(False)。例如: 1大于2是假,1大于0是真
复数(关键字complex)
type(变量名):查看变量数据类型

案例:

# 根据业务场景来决定 酒店管理系统(整数),超市管理系统--价格(小数)
phone_price = 899
print(type(phone_price))  #<class 'int'>

f_price = 3.5895159690318690315
print(type(f_price))  #<class 'float'>

# 结合判断、循环使用
# 登录,判断用户名==admin并且密码==123456,登录成功,否则登录失败
bol = True
boll = False
print(type(bol))  #<class 'bool'>

# 复数:了解即可
age  = 10+0j
print(type(age))   #<class 'complex'>

age1  = 0j
print(type(age1))

2. 字符串类型

2.1 字符串

字符串定义:凡是由引号引起来的内容就是字符串,引号可以是单引号,双引号,三引号。
单引号,双引号,三引号区别?
统计字符串的长度:len(变量名)
# 'python'是最容易入门的语言
str1 = "'python'是最容易入门的语言"
print(str1)
str2 = 'py"th"on是最容易入门的语言'
print(str2)
str3 = ''''python'是最容易入门的语言'''
print(str3)

str4 = '    床前明月光,' \
       '     疑是地上霜,' \
       '     举头望明月,' \
       '     低头思故乡    '
print(str4)

str5 = ''' 床前明月光,
    疑是地上霜,
    举头望明月,
    低头思故乡'''
print(str5)
特殊字符的处理:不要记忆,只要对内容的颜色进行查看
    \n : 换行
    \t: tab
    
   在特殊字符前面加上\,转义 
   在整个字符串前面加上r、R
str1 = '\thello \n python'
print(str1)

str2 = 'hello \\n python'  # hello \n python
print(str2)

str3 = R'\thello \n python'  # \thello \n python
print(str3)

url = r'E:\A测试\04 文件\01 Python编程技术\02 Python的基本数据类型'
print(url)

# 不同的数据类型是不能进行运算
num1 = '100'
str1 = 3
# print(num1 + str1)
print(num1 * str1)
总结:
   字符串相加,字符串的拼接
   字符串和整数相乘,字符串的多次输出

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值