Home > Backend Development > Python Tutorial > Python - basic data types

Python - basic data types

高洛峰
Release: 2016-10-19 11:35:56
Original
1153 people have browsed it

Simple data types and assignments

Variables do not need to be declared

Python variables do not need to be declared, you can directly enter:

>>>a = 10
Copy after login

Then you will have a variable a in your memory, and its value is 10, its type is integer (integer). You don't need to make any special declarations before this, and the data type is automatically determined by Python.

>>>print a
>>>print type(a)
Copy after login

Then there will be the following output:

10

Here, we learned a built-in function type() to query the type of a variable.

Recycle variable names

If you want a to store different data, you can assign the value directly without deleting the original variable.

>>>a = 1.3
>>>print a,type(a)
Copy after login

There will be the following output

1.3

We see another usage of print, that is, print is followed by multiple outputs, separated by commas.

Basic data types

a=10         # int 整数
a=1.3        # float 浮点数
a=True       # 真值 (True/False)
a='Hello!'   # 字符串
Copy after login

The above are the most commonly used data types. For strings, double quotes can also be used.

(In addition, there are other data types such as fractions, characters, plurals, etc. If you are interested, you can learn about it)

Summary

Variables do not need to be declared or deleted, and can be directly recycled and applied.

type(): Query data type

integer, floating point number, true value, string


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template