程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Common data types in Python

編輯:Python

Common data types

Integer type -> int
Can represent a positive number 、 negative 、0 The representation of integers in different base numbers Decimal system -> Default base , No special indication is required Binary system -> With 0b start octal -> With 0o start Hexadecimal -> With 0x start Base number Basic numbers Several in a row Representation form Decimal system 0,1,2,3,4,5,6,7,8,9 10 11 Binary system 0,1 2 0b11111111 octal 0,1,2,3,4,5,6,7 8 0o1544 Hexadecimal 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F 16 0x11
# -----------python Data types commonly used in -----------
# Integers can be expressed as binary 、 octal 、 Decimal system 、 Hexadecimal
print(1)
print(0b11111111) # 2 Base number ,0b start
print(0o1544) # 8 Base number ,0o start
print(0xFFFF) # 16 Base number ,0x start
Floating point numbers -> float
Floating point numbers are composed of integer parts and decimal parts Floating point storage imprecision When calculating with floating-point numbers , The number of decimal places may be uncertain , Because the computer uses binary to store , Floating point numbers are stored imprecisely , There will be some errors
# Floating point numbers 
print(1.1+2.2) # 3.300000000000003
print(1.1+2.1) # 3.2

resolvent

The import module decimal

from decimal import Decimal
print(Decimal('1.1')+Decimal('2.2'))
Boolean type -> bool
A value used to indicate true or false True Express as true ,False Said the false Boolean values can be converted to integers True by 1,False by 0

# Boolean type 
print(True+1) # 2
character string -> str
Strings are also called immutable character sequences You can use single quotes 、 Double quotes 、 Three quotation marks to indicate The string defined by single quotation marks and double quotation marks must be on one line A string defined by three quotation marks can be distributed on multiple consecutive lines
# character string 
str1 = ' character string '
str2 = " String string string "
str3 = ''' character string
character string '''
print(str1, str2, str3)
 

python More articles on common data types

  1. Python Way of learning 【 Second articles 】-pyc brief introduction 、Python Common data types and their usage and common operators

    1.pyc brief introduction python The program also has a compilation process at run time , After compiling, it will produce .pyc file . This is a kind of by python Binary files executed by the virtual machine ( Bytecode ), Used to save in memory PyCodeObject, In order to speed up the loading and running of the program . ...

  2. Python Common data types

    Python There are many commonly used data types , Today, I will briefly introduce these three kinds of ,int( Integer types ).str( character string ).bool( Boolean type ) One .int( Integer types )1. Without decimals ,integer Abbreviation , Often used in the calculation or size of data ...

  3. Python The foundation of development Python Common data types

    One .Python Introduce Python It's a dynamically interpreted programming language .Python It's easy to learn . Powerful . Support for object-oriented . Functional programming , Can be in Windows.Linux And other operating systems , meanwhile Python Can be in J ...

  4. python Introduction to common data type built-in methods

    Have a good command of python Common data type built-in method is an internal skill that every beginner must possess . Here's how python Common types of centralized data and their methods , Open source code , The main methods are annotated in Chinese . One . integer a = 100 a.xx ...

  5. python Commonly used data types

    1.  Definition and declaration of variables Before learning variables , We need to know the rules for naming variables : ①  Variables must be composed of numeric and alphabetic underscores , Such as a_1 ②  Variable name cannot start with a number , Such as 1a ③  The hump nomenclature needs to be followed Assigning a value to a variable usually uses “=”, ...

  6. python Basic data types

    One .python List of data types in 1. list List is one of the most commonly used data types in the future , Through the list can achieve the most convenient storage of data . Modification and other operations Two . List common operations > section > Additional > Insert > modify & ...

  7. python Basic data types ( One )

    Python3 Numbers (Number) Definition :a=1 characteristic : 1. Only one value can be stored 2. Once defined , Non modifiable 3. Direct access classification : integer , Long integer , Boolean , floating-point , The plural python2.* And python3.* About the whole ...

  8. python Commonly used libraries

    This paper is written by Bole Online - AI Lingfeng translate ,Namco proofread . Unauthorized , Prohibited reproduced ! English source :vinta. Welcome to the translation group . Awesome Python , This is another Awesome XXX Series of resources , from ...

  9. Python Common built-in modules

    Python Common built-in modules datetime Standard library for processing dates and times . be aware datetime It's a module ,datetime The module also contains a datetime class , adopt from datetime import da ...

  10. Day05 - Python Common modules

    1. Module introduction Module is a save Python Code files . Modules can define functions , Classes and variables . Modules can also contain executable code . Module is also Python object , Has a random name attribute for binding or referencing . The following example is a simple module ...

Random recommendation

  1. js Type conversion

    1. == Type conversion and then judgment . true Is converted to 1,false Is converted to 0 And then judge == true false == true true === false false == fal ...

  2. SQL Create a new table based on the existing table

    SQL Create a new table from an existing table , The new table structure should be the same as the existing one , But don't use the data in the existing table ! perform DML Statement depends on the type of database : SQLITE ----- Copy table structure and data to new table CREATE TABLE TA ...

  3. About C# Chinese text template (.tt) Simple application of

    These two days, I've been working on a project .tt file , I haven't touched before ,so Inquiry, study, take notes , Help memory and latecomers . Click Select text template in project add Post the code below , A simple comment is made <#@ template debug=" ...

  4. VC++ How to register and unload with code in the program ocx Control ( Code )

    Method 1 : stay dos or Windows Run... From the command line :regsvr32 ocxname.ocx register Example :regsvr32 netshare.ocx     // register netshare.ocx Control regsvr ...

  5. Android Multi state button ToggleButton

    ToggleButton       Selected state , The status is not selected and different display text needs to be set for different statuses .       attribute :           checked="true"         ...

  6. cocos3——8. Implementation of a beginner's Guide

    1. use ClippingNode Clipping range Write crop interface : function createClipNode(node, stencil, inverted) { var clip_node = new c ...

  7. [BZOJ]4199 Wine tasting Conference (Noi2015)

    Make sense is the suffix array bare question , Although we know the principle of suffix array, it is small C Can't write what the hell .. Small C While doing this problem , Learned about suffix array . The suffix array template on the network doesn't understand how to break , Copy the whole process according to Huang Xuechang's code , I feel that Mr. Huang wrote very ...

  8. Python_ Syntax and interface design

    http://www.runoob.com/python/python-gui-tkinter.html  http://www.python-course.eu/python_tkinter.php

  9. SqlServer Query a data in a table or a column

    create proc spFind_Column_In_DB ( @type int,-- type : For text type . Is the numerical type @str nvarchar(100)-- Name to search for ) as -- Create a temporary ...

  10. Answer key -bzoj4221 JOI2012kangaroo

    Problem bzoj The question : Given \(n\) A kangaroo , Each kangaroo has two attributes \(a,b\), if \(a_i\leq b_j\), be \(i\) Yes, it can be. \(j\) It's in the bag , After a series of placement operations, the operation cannot be carried out ...


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved