python数值类型_Python数值类型

python数值类型

In programming, Data Types are an essential concept. Data of various types can be stored in variables as per the task we want the variables to perform.

在编程中,数据类型是必不可少的概念。 根据我们希望变量执行的任务,各种类型的数据可以存储在变量中。

The built-in data types in Python are

Python中的内置数据类型是

  • Text Type

    文字类型

  • Numeric Type

    数值类型

  • Mapping Type

    映射类型

  • Sequence Type

    序列类型

  • Set Type

    设定类型

  • Boolean Type

    布尔型

  • Binary Type

    二进制类型

In this tutorial, we are going to learn about the various numeric types in Python with examples.

在本教程中,我们将通过示例学习Python中各种数字类型

To store numeric values, we need specific numeric data types. Python has some of the data types to define numeric values – these numeric data types can be used to store various numeric values.

要存储数值,我们需要特定的数值数据类型。 Python具有一些用于定义数值的数据类型-这些数值数据类型可用于存储各种数值。

There are 3 numeric data types in Python:

Python中有3种数字数据类型:

  1. int

    整型

  2. float

    浮动

  3. complex

    复杂

1)int (1) int)

Integer numeric type is used to store signed integers with no decimal points, like -5, 2, 78, etc.

整数数字类型用于存储无小数点的带符号整数,例如--5、2、78等。

Example:

例:

# Assigning integer values to Variables
x = 8
y = -9
# Manipulating the value of x
x = x + y
# Prints the updated value of x
print("x= ", x)
# Prints the Data Type of x
print("Data type of x: ", type(x))

Output

输出量

x=  -1
Data type of x:  <class 'int'>

2)浮动 (2) float)

Float numeric type is used to store floating-point values like 6.66, 58.9, 3.14, etc. Floats can also be in scientific notation, with E or e indicating the power of 10 (3.6e3 = 3.6x 10= 3600).

浮点数字类型用于存储浮点值,例如6.66、58.9、3.14等。浮点数也可以用科学计数法表示,E或e表示10的幂(3.6e3 = 3.6x 10 3 = 3600)。

Example:

例:

# Assigning float values to Variables
x = 8.9
y = -9.1
# Manipulating the value of x
x = x - y
# Prints the updated value of x
print("x= ", x)
# Prints the Data Type of x
print("Data type of x: ", type(x))

Output

输出量

x=  18.0
Data type of x:  <class 'float'>

3)复杂 (3) complex)

Complex numeric type is used to store complex numbers like 3.14j, 8.0 + 5.3j, 2+6j etc.

复数类型用于存储复数,例如3.14j,8.0 + 5.3j,2 + 6j等。

Format: Real + Imaginary component j

格式:实数+虚数j

Note: The imaginary component of a complex number must be denoted by j. If we denote it using i it is considered as invalid syntax in Python.

注意:复数的虚部必须由j表示。 如果使用i表示它,则在Python中被视为无效语法。

Example:

例:

# Assigning complex values to Variables
x = 1+8.5j
y = 4+9j
# Manipulating the value of x
x = x + y
# Prints the updated value of x
print("x= ", x)
# Prints the Data Type of x
print("Data type of x: ", type(x))

Output

输出量

x=  (5+17.5j)
Data type of x:  <class 'complex'>

演示所有数值数据类型的示例 (Examples demonstrating all numeric data types)

Let's look at some simple Python programs to demonstrate the numeric data types:

让我们看一些简单的Python程序来演示数字数据类型:

Note: type() is a function used to determine the type of a variable

注意: type()是用于确定变量类型的函数

Example 1: Program to print the data types of variables

示例1:打印变量数据类型的程序

# Assigning Values to Variables
a = 10
b = -1
c = 15.9
d = 6 + 8j
# Printing data type of the Variables
print("Data Type of a: ", type(a))
print("Data Type of b: ", type(b))
print("Data Type of c: ", type(c))
print("Data Type of d: ", type(d))

Output

输出量

Data Type of a:  <class 'int'>
Data Type of b:  <class 'int'>
Data Type of c:  <class 'float'>
Data Type of d:  <class 'complex'>

Example 2: Program to add complex numbers to integer and float type numbers

示例2:将复数添加到整数和浮点型数字的程序

a = 2 + 9j  # complex number
b = 2.8     # floating point number
c = 9       # integer
# addition of complex and integer
comp_plus_int = a + c
# addition of complex and float
comp_plus_float = a + b
# Printing result of addition and 
# datatype of the result
print("Sum of complex and integer values= ",comp_plus_int)
print("Data Type After addition: ", type(comp_plus_int))
print()
print("Sum of complex and float values= ", comp_plus_float)
print("Data Type After addition: ", type(comp_plus_float))

Output

输出量

Sum of complex and integer values=  (11+9j)
Data Type After addition:  <class 'complex'>
Sum of complex and float values=  (4.8+9j)
Data Type After addition:  <class 'complex'>

翻译自: https://www.includehelp.com/python/numeric-types.aspx

python数值类型

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540590.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[转载] Python高级变量(列表、元组、字典、字符串、公共方法)

参考链接&#xff1a; Python | 重点数据类型 (字符串&#xff0c;列表&#xff0c;元组&#xff0c;迭代)(String, List, Tuple, Iteration) 文章目录 高级变量类型目标知识点回顾 01. 列表1.1 列表的定义1.2 列表常用操作del 关键字&#xff08;科普&#xff09;关键字、函数…

python 操作mongodb数据库参考文档

参考文档链接&#xff1a;https://pypi.python.org/pypi/pymongo pymongo的参考文档http://api.mongodb.com/python/current/tutorial.html mongoengine的参考文档&#xff1a;https://pypi.python.org/pypi/mongoengine#downloads Flask-MongoEngine的参考文档&#xff1a;htt…

php eot eod_EOD的完整形式是什么?

php eot eodEOD&#xff1a;一天结束 (EOD: End Of Day) EOD is an abbreviation of "End Of Day". EOD是“ End Of Day”的缩写 。 It is an expression, which is commonly used in the Gmail platform. In a particular mail, if the sender wants to give the d…

[转载] python元组 tuple

参考链接&#xff1a; Python元组Tuple 类型特点&#xff1a;可以存放多个、 可以重复的&#xff0c;有顺序的数据&#xff0c;数据不可变。 如果项目中需要定义多个数据到一个变量中存放 存放的数据&#xff0c;在项目运行过程中&#xff0c;会发生数据的增加、修改、删除…

aio nio aio_AIO的完整形式是什么?

aio nio aioAIO&#xff1a;多合一 (AIO: All-in-one) AIO is an abbreviation of "all-in-one", which is also known as an MFP (multi-function product/printer/peripheral), multi-functional or multi-function device (MFD). It is a workplace machine that …

[转载] python基础入门二

参考链接&#xff1a; Python集合Set 写代码,有如下变量,请按照要求实现每个功能 &#xff08;共6分&#xff0c;每小题各0.5分&#xff09; name ” aleX” 1)移除 name 变量对应的值两边的空格,并输出处理结果 2) 判断 name 变量对应的值是否以 “al” 开头,并输出结果
…

组合数据类型练习,英文词频统计实例上

1、字典实例&#xff1a;建立学生学号成绩字典&#xff0c;做增删改查遍历操作。 建立&#xff1a; d{0001:99,0003:89,0004:98,0005:100,0006:78} 增&#xff1a;d[0002]79 删&#xff1a;d.pop(0001) 改&#xff1a;d[0004]100 查&#xff1a;print(d[0002]) 遍历操作&#x…

茱莉亚分形_茱莉亚的NaN Constant

茱莉亚分形Julia| NaN / Nan64常数 (Julia | NaN/Nan64 Constant) Nan / Nan64 is a constant of the Float64 type in Julia programming language, it represents "not-a-number" value. Nan / Nan64是Julia编程语言中Float64类型的常量&#xff0c;它表示“非数字…

[转载] Python3 数组

参考链接&#xff1a; Python中的Array | 数组1(简介和功能) 一、list和array的区别 Python的数组通过Numpy包的array实现。 Python里二者最大的区别是&#xff0c;list可以存储不同类型的数据&#xff0c;而array只能存储相同类型的数据。 import numpy #直接定义 a […

201671010128 2017-09-24《Java程序设计》之继承

1.继承的概念及理解&#xff1a; 继承是java面向对象编程技术的一块基石&#xff0c;因为它允许创建分等级层次的类。继承就是子类继承父类的特征和行为&#xff0c;使得子类对象&#xff08;实例&#xff09;具有父类的实例域和方法&#xff0c;或子类从父类继承方法&#xff…

紫外线的形式是什么?

紫外线&#xff1a;紫外线 (UV: Ultraviolet) UV is an abbreviation of Ultraviolet. In RO water purifiers, the bacteria or germs which are present in the water cannot get killed by reverse osmosis process but this process can banish the dissolved solids and i…

[js高手之路] html5 canvas系列教程 - 掌握画直线图形的常用API

我们接着上文[js高手之路] html5 canvas系列教程 - 认识canvas以及基本使用方法继续. 一、直线的绘制 cxt.moveTo( x1, y1 )&#xff1a; 将画笔移动到x1, y1这个点 cxt.lineTo( x2, y2 )&#xff1a;将画笔从起点开始画直线&#xff0c;一直画到终点坐标( x2, y2 ) cxt.stroke…

金矿问题

Description: 描述&#xff1a; This is a standard interview problem featured in interview coding rounds of Amazon, Flipkart. 这是亚马逊Flipkart的采访编码回合中的标准采访问题。 Problem statement: 问题陈述&#xff1a; Given a gold mine of n*m dimensions, e…

[转载] python中的数组类型及特点

参考链接&#xff1a; Python中的Array | 数组2(简介和功能) 名称 表示方法示例 是否有序 函数方法&#xff08;增删等&#xff09; 特点 List 类型表示&#xff1a;L L [Adam, 95.5, Lisa, 85] 有序 增加&#xff1a;&#xff08;1&#xff09;L.append(Paul),增加…

puppet

Puppet前期环境&#xff08;网络、解析、yum源、NTP&#xff09;在上一章节已经准备就绪&#xff0c;接下来我们就开始安装Puppet了&#xff0c;安装Puppet其实很简单&#xff0c;官方已经提供了yum源&#xff0c;只需要自己将所需要的安装包下载下来然后做成本地yum源即可使用…

[转载] 【数学问题】利用python求解表达式

参考链接&#xff1a; Python 变量 &#xff5c;表达式 &#xff5c;条件和函数 有时候我们会遇到一些很复杂的表达式&#xff0c;或者想要求解某个表达式&#xff0c;但是手动计算的话不但耗时还费精力&#xff0c;我们能不能利用计算机来帮助我们进行计算呢&#xff1f; 1…

cesium广告牌_公路广告牌

cesium广告牌Description: 描述&#xff1a; This is a standard dynamic programing problem of finding maximum profits with some constraints. This can be featured in any interview coding rounds. 这是在某些约束条件下找到最大利润的标准动态编程问题。 这可以在任何…

你和大牛差了啥

mmp。无时无刻不在想和大牛差在哪里了。别人为什么可以那么牛逼而你tmd那么菜&#xff01;整个人顿时都颓废了。啥事儿不想干。后来想了想感情就是他比较黑吧。

[转载] python数组的使用

参考链接&#xff1a; Python中整数的最大可能值是多少&#xff1f; 原文地址为&#xff1a; python数组的使用 python数组的使用 python数组的使用 2010-07-28 17:17 1、Python的数组分三种类型&#xff1a; (1) list 普通的链表&#xff0c;初始化后可以通过特定方法…

scala中循环守卫_Scala中的循环

scala中循环守卫Scala中的循环 (Loops in Scala) In programming, many times a condition comes when we need to execute the same statement or block of code more than one time. It could be difficult to write the same code multiple times, so programing language d…