Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize data type determination in python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to achieve data type determination in python, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

First, judge the data type

0, type (x)

Type () can take anything as an argument-- and return its data type. Integers, strings, lists, dictionaries, tuples, functions, classes, modules, and even type objects can be accepted by type functions as parameters.

> > type (1)

> li = []

> type (li)

> import odbchelper

> type (odbchelper)

> import types

> type (odbchelper) = = types.ModuleType

True

II. Data type conversion

1. Chr (I)

The chr () function returns the string corresponding to the ASCII code.

Print chr (65)

A

Print chr (66)

Print chr (65) + chr (66)

AB

2. Complex (real [, imaginary])

The complex () function converts a string or number into a plural.

> complex ("2percent 1j")

(2x 1J)

> complex ("2")

(20.0j)

> complex (2Pol 1)

(2x 1J)

> complex (2Lp1)

(2x 1J)

3. Float (x)

The float () function converts a number or string into a floating point number.

> float ("12")

12.0

> > float (12L)

12.0

Float (12.2)

12.199999999999999

4. Hex (x)

The hex () function converts integers to hexadecimal numbers.

> > hex (16)

'0x10'

> hex

'0x7b'

5. Long (x [, base])

The long () function converts numbers and strings into integers, with base as an optional cardinality.

> long ("123")

123L

> > long (11)

11L

6. List (x)

The list () function converts sequence objects into lists. Such as:

> list ("hello world")

['hackneyed,' estranged, 'lumped,' lumped, 'oiled,' wicked, 'oiled,' rusted, 'lumped,' d']

>

[1, 2, 3, 4]

7. Int (x [, base])

The int () function converts a number and a string into an integer, with base as an optional cardinality.

> int

three

Int (3L)

three

> int ("13")

thirteen

> > int ("14", 15)

nineteen

8. Min (x [, yjinz.])

The min () function returns the minimum value of a given parameter, which can be a sequence.

> min (1, 2, 3, 4)

one

> min ((1, 2, 3), (2, 3, and 4))

(1, 2, 3)

9. Max (x [, YJI z...])

The max () function returns the maximum value of a given parameter, which can be a sequence.

> max (1, 2, 3, 4)

four

> max ((1, 2, 3), (2, 3, and 4))

(2, 3, 4)

10. Oct (x)

The oct () function converts the given integer to an octal number.

> > oct (8)

'010'

> oct

'0173'

11. Ord (x)

The ord () function returns the ASCII code or Unicode value of a string parameter.

> > ord ("a")

ninety-seven

> ord (u "a")

ninety-seven

12. Str (obj)

The str () function converts an object into a printable string.

> str ("4")

'4'

> > str (4)

'4'

> str (3x2j)

'(3' 2j)'

13. Tuple (x)

The tuple () function converts sequence objects into tuple.

> tuple ("hello world")

('hackneyed,' estranged, 'lumped,' lumped, 'oiled,' wicked, 'oiled,' rusted, 'lumped,' d')

> tuple ([1, 2, 3, 4])

(1, 2, 3, 4)

The above is how to implement data type determination in python. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report