Python variable and Data Type Details, python variable data type
Python variables and Data Types
- Data Types in Python
- Print Statement of Python
- Python annotations
- What is a variable in Python?
- Define strings in Python
- Raw string and Multiline string in Python
- Unicode string in Python
- Integer and floating point number in Python
- Boolean Type in Python
Data Types in Python
As the name suggests, a computer is a machine that can be used for mathematical computation. Therefore, a computer program can naturally process various numerical values. However, computers can process a variety of data, such as text, graphics, audio, video, and web pages. Different data types need to be defined. In Python, the following types of data can be processed directly:
I. Integer
Python can process Integers of any size, including negative integers. in Python, the expression of integers is the same as that in mathematics, such as 1,100,-80, and 0.
Because the computer uses binary data, it is convenient to express integers in hexadecimal format. The hexadecimal format uses the 0x prefix and 0-9, and af, for example, 0xff00, 0xa5b4c3d2, and so on.
Ii. Floating Point Number
A floating point is also a decimal point. It is called a floating point because the decimal point of a floating point is variable according to the scientific notation. For example, 1.23x10 ^ 9 and 12.3x10 ^ 8 are equal. Floating point numbers can be written in mathematics, such as 1.23, 3.14,-9.01, and so on. However, large or small floating point numbers must be represented by scientific notation, replacing 10 with e. 1.23x10 ^ 9 is 1.23e9, or 12.3e8, 0.000012 can be written as 1.2e-5, and so on.
Integers and floating-point numbers are stored in computers in different ways. Integer operations are always accurate (is Division accurate? Yes !), Floating-point operations may have rounding errors.
Iii. String
A string is any text enclosed by ''or" ", such as 'abc' and" xyz. Note that ''or" "is only a representation, not a part of the string. Therefore, the string 'abc' contains only three characters: a, B, and c.
Iv. Boolean Value
The Boolean value is exactly the same as that of the Boolean algebra. A boolean value can only be True or False, either True or False. in Python, values of True and False can be used to represent boolean values (case-sensitive) or computed using Boolean operations.
Boolean values can be calculated using and, or, and not.
The and operation is an operation. Only True is used for all operations, and True is used for all operations.
Or is an or operation. If either of them is True, or is True.
The not operation is not an operation. It is a single-object operator that converts True to False and False to True.
5. null values
A null value is a special value in Python, expressed as None. None cannot be understood as 0, because 0 is meaningful, and None is a special null value.
In addition, Python provides multiple data types, such as lists and dictionaries, and allows you to create custom data types.
Exercise code
1. Calculate the sum of the decimal integer 45678 and the hexadecimal integer 0x12fd2. Print 45678 + 0x12fd22. Use a string to indicate Learn Python in imooc. Print "Learn Python in imooc" 3. Calculate the Boolean value of the following expression (note = indicates determining whether the values are equal): print 100 <99 print 0xff = 255 result: False True
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!