Home Backend Development Python Tutorial Python - basic data types

Python - basic data types

Oct 19, 2016 am 11:35 AM
python Base Tutorial type of data

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


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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to download deepseek Xiaomi How to download deepseek Xiaomi Feb 19, 2025 pm 05:27 PM

How to download deepseek Xiaomi

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Jul 01, 2024 am 07:22 AM

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

In summer, you must try shooting a rainbow

How do you ask him deepseek How do you ask him deepseek Feb 19, 2025 pm 04:42 PM

How do you ask him deepseek

How to search deepseek How to search deepseek Feb 19, 2025 pm 05:18 PM

How to search deepseek

What software is NET40? What software is NET40? May 10, 2024 am 01:12 AM

What software is NET40?

What language is the browser plug-in written in? What language is the browser plug-in written in? May 08, 2024 pm 09:36 PM

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 How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer Jul 16, 2024 pm 09:02 PM

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

See all articles