百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

Python数据类型详解(python数据类型包括哪三种)

off999 2024-10-31 13:58 27 浏览 0 评论

·

数据类型:

  • 数值数据类型:int、float、complex。
  • 字符串数据类型:str。
  • 序列类型:list、tuple、range。
  • 二进制类型:bytes、bytearray、memoryview。
  • 映射数据类型:dict。
  • 布尔类型:bool。
  • 集合数据类型:set、frozenset。
#Data Type
#String
print("Hello" [3])
print("Hello" + "world")
#Integer 
print(123 + 258)
#Float
print(1.23 + 25.8)

print(1.23 - 25.8)

#Boolean = TRUE/FALSE

项目 1:输入 Name 并将数字打印为字符。

no_char = len(input("What is your name?"))
#Converting integer into string 
new_no_char =  str(no_char)
print("Your name has "+ new_no_char + " characters.")

no_char = str(len(input("What is your name?")))

print("Your name has "+ no_char + " characters.")
>>

What is your name?Nidhi
Your name has 5 characters.

数据类型:数字相加 + 浮点数

a= float(123)
print(type(a))
print(70 +  float("100.25"))

>>
<class 'float'>
170.25
#This is string
print(str(152) + str(528))

>>
152528
print(3+5)
print(8-6)
print(6*4)
print(86/2)
print(2**5)

>>
8
2
24
43.0
32

计算的执行顺序: ??

#PEMDASLR 

#PRIORITY 1 : ()
#PRIORITY 2: **
#PRIORITY 3: * / 
#PRIORITY 4: + -
print(3*3+3/3-3)
>>
7.0
print(3*(3+3)/3-3)
>>
3.0

项目 2:计算 BIM(体重指数)

height = input("What is your height?")
weight = input("What is your weight?")
height_as_flot = float(height)
weight_as_int =  int(weight)
bmi = str(int(weight_as_int / height_as_flot ** 2 ))

print("Your Body Mass Index is " + bmi)

>>

What is your height?6.4
What is your weight?48
Your Body Mass Index is 1
  1. 对数字进行四舍五入
print(8/3)
>>
2.6666666666666665

差异

print(round(8/3))

>>
3

2. 将上述计算转换为整数

print(8//3)

>>
2

3. 基于其先前值的操纵值

score= 0 
score += 1
print(score)

>>
1
score= 0 
score += 1
score += 1
print(score)

>>
2

f 字符串 :

f-strings(格式化字符串文字)是一种在 Python 中将表达式嵌入字符串文字的方法,使用大括号 {}。

score= 0 
score += 1

height = 1.8
is_winning = True

print(f"Your score is {score}, your height is {height}, and your are winning is {is_winning}.")

>>
Your score is 1, your height is 1.8, and your are winning is True.

项目 3:计算人生剩余的时间

age = input("What is your age?")

years = 90 - int(age)
weeks = years*52
days = years*365

print(f"You have {weeks} weeks and {days} days left.")

>>
What is your age?42
You have 2496 weeks and 17520 days left.

检查数据类型:

a = int("28") / int(52.85)

print(type(a))

>>

<class 'float'>

项目 4:欢迎使用小费计算器!

print("Welcome to tip calculator!\n")

bill = float(input("What was the total bill? \n#34;))

tip = int(input ("How much tip would you like to give? 10,12 or 15?\n%"))

no_of_people = int(input("How many people to split the bill? \n"))

total_and_tip = tip / 100 * bill + bill

final_bill = total_and_tip / no_of_people

print(f"Each person should pay: {final_bill}")

>>

Welcome to tip calculator!

What was the total bill?
$100
How much tip would you like to give? 10,12 or 15?
%10
How many people to split the bill?
2
Each person should pay: 55.0

如果需要 2 个十进制值:

print("Welcome to tip calculator!\n")

bill = float(input("What was the total bill? \n#34;))

tip = int(input ("How much tip would you like to give? 10,12 or 15?\n%"))

no_of_people = int(input("How many people to split the bill? \n"))

total_and_tip = tip / 100 * bill + bill

bill_final_bill = total_and_tip / no_of_people

final_bill = "{:.2f}".format(bill_final_bill)  #WE ARE FORMATING

print(f"Each person should pay: {final_bill}")

>>

Welcome to tip calculator!

What was the total bill? 
$100
How much tip would you like to give? 10,12 or 15?
%10
How many people to split the bill? 
2
Each person should pay: 55.00

相关推荐

戴尔官网保修查询入口(戴尔售后保质期查询)

可以按照以下步骤查询戴尔笔记本电脑的保修期:1.打开戴尔官网:https://www.戴尔.com/zh-cn/售后服务/保修政策.html2.点击页面上方的“服务与支持”按钮,进入戴尔的服务支持...

手机号邮箱登录入口(手机号邮箱官网)

手机163邮箱登录入口如下:163邮箱官网入口:https://smart.mail.163.com/login.htm点击进入登录或者注册邮箱即可。手机浏览器访问进入官网http://www.123...

sd卡(sd卡无法读取怎么修复)

  SD卡是大卡,相机用的;普通的手机内存卡,是小卡,正规的名称是macrosd卡,也就是微型SD卡。可以通过卡套转为普通的SD卡的大小。  其实就是大小不同。但手机上的内存卡,人们经常也俗称为SD...

路由器连接图(网络路由器连接图)
  • 路由器连接图(网络路由器连接图)
  • 路由器连接图(网络路由器连接图)
  • 路由器连接图(网络路由器连接图)
  • 路由器连接图(网络路由器连接图)
windows7蓝牙功能在哪里打开

点击搜索框在windows7系统主界面点击开始菜单,点击打开搜索框。输入命令输入services.msc后回车,在列表中找到并右击BluetoothSupportS...点击属性选择进入属性菜单,...

2010激活密钥(microsoft2010激活密钥)
2010激活密钥(microsoft2010激活密钥)

步骤/方式1officeprofessionalplus2010:(office专业版)6QFdx-pYH2G-ppYFd-C7RJM-BBKQ8Bdd3G-xM7FB-Bd2HM-YK63V-VQFdKVYBBJ-TRJpB-QFQ...

2025-11-19 04:03 off999

联想官方刷新bios工具(联想电脑刷新bios)

刷新BIOS需要使用联想的官方网站或授权维修中心来进行操作。以下是一些基本步骤:1.访问联想的官方网站,找到BIOS更新程序并下载。在下载过程中,请确保选择与您计算机型号匹配的版本。2.将下载的B...

苹果ios14系统下载(苹果ios14.1下载)
苹果ios14系统下载(苹果ios14.1下载)

1方法一步骤/方式一打开Appstore。步骤/方式二在搜索栏点击搜索框。步骤/方式三搜索并点击需要下载的软件。步骤/方式四点击获取。步骤/方式五最后验证ID密码即可。1.在应用商店搜索你要下载的应用名称。2.点击下载按钮,如果要求登...

2025-11-19 03:03 off999

office2010怎么免费永久激活密钥

用这个试试,一个KMS激活工具可以激活2010到2019的Office自家的目前用的就是这个microsoft6477.moe/1716.html直接使用这个Microsoftoffice2010...

类似爱加速的国内ip(类似爱加速的app)
类似爱加速的国内ip(类似爱加速的app)

推荐“V8盒子”。这一款免费无广告的模拟器,不同于其它软件盒子,而是类似于X8沙箱,满足游戏多开,画中画,悬浮球操作,熄屏后台运行等多功能的沙箱盒子.支持一键root,一键安装xposed框架,能在安卓/苹果手机上运行多个安卓/ios虚拟系...

2025-11-19 02:03 off999

阿里旺旺手机客户端(阿里旺旺手机app)

手机淘宝的旺旺在打开商品后,会看到左下角有个旺旺的图标,点击就可以联系了。  阿里旺旺是将原先的淘宝旺旺与阿里巴巴贸易通整合在一起的一个新品牌。它是淘宝和阿里巴巴为商人量身定做的免费网上商务沟通软件,...

最纯净的pe装机工具(pe工具哪个纯净)

U盘装系统步骤:1.制作U盘启动盘。这里推荐大白菜U盘启动盘制作工具,在网上一搜便是。2.U盘启动盘做好了,我们还需要一个GHOST文件,可以从网上下载一个ghost版的XP/WIN7/WIN8系统,...

装一个erp系统多少钱(wms仓库管理软件)

现在主流有客户端ERP和云端ERP两种客户端通常一次买断,价格在万元左右,但是还有隐性费用,你需要支付服务器、数据管理员,此外如果系统需要更新维护,你还需要支付另外一笔不菲的费用。云端ERP:优势...

cad2014序列号和密钥永久(autocad2014序列号和密钥)

1在cad2014中修改标注样式后,需要将其保存2单击“样式管理器”按钮,在弹出的窗口中选择修改后的标注样式,然后单击“设置为当前”按钮,再单击“保存当前样式”按钮,将其保存为新的样式名称3为了...

qq修改密保手机号(qq修改密保手机号是什么意思)

QQ更改绑定的手机号码操作步骤如下:1、打开手机主界面,找到“QQ”软件点击打开。2、输入正确的QQ账户和密码登录到qq主界面。3、点击左上角的头像“图片”,进入到个人中心界面。4、进入到个人中心界面...

取消回复欢迎 发表评论: