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 103?= 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.pswp.cn/news/540590.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540590.shtml
英文地址,請注明出處:http://en.pswp.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…