Python - basic data types
Oct 19, 2016 am 11:35 AMSimple 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
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)
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)
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!' # 字符串
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

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

In summer, you must try shooting a rainbow

What language is the browser plug-in written in?

How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer
