In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "binary conversion and string conversion in Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
One ten turns two
Convert decimal to binary:
> > bin (10)
'0b1010'
2 ten to eight
Convert decimal to octal:
> oct (9)
'0o11'
Three ten to sixteen
Convert decimal to hexadecimal:
Hex (15)
'0xf'
4 string to byte
Convert string to byte type
> s = "apple"
> bytes (srecoery encodingbirds utfmur8')
Baked apple`
5 converted to a string
Convert character types, numeric types, etc., to string types
> I = 100
> str (I)
'100'
6 + 10 rpm ASCII
ASCII characters corresponding to decimal integers
Chr (65)
'A'
7 ASCII to 10
Decimal number corresponding to ASCII character
> ord ('A')
sixty-five
8 convert to a dictionary
Several methods of creating data dictionary
> > dict ()
{}
> dict (axioms, girls, books, books, etc.)
{'await:' await, 'baked:' b'}
> dict (zip (['axiaojingzhongb'], [1pd2]))
{'averse: 1,' baked: 2}
> dict ([('axiaojin1), (' baked page2)]))
{'averse: 1,' baked: 2}
9 convert to floating point type
Convert an integer or numeric string to a floating point number
> > float (3)
3.0
If it cannot be converted to a floating point number, it will report ValueError:
> float ('a')
Traceback (most recent call last):
File "", line 1, in
Float ('a')
ValueError: could not convert string to float:'a'
10 convert to integer
Int (x, base = 10)
X may be a string or numeric value, converting x to an integer.
If the parameter is a string, it may contain symbols and decimal points.
If the integer representation is outside the range, a long integer is returned.
> int
eighteen
11 turn into a collection
Returns a set object. Duplicate elements are not allowed in the collection:
> a = [1, 4, 2, 3, 1]
> > set (a)
{1, 2, 3, 4}
12 turn to slice
Class slice (start, stop [, step])
Returns a slice object with an index set specified by range (start, stop, step), making the code more readable.
> a = [1, 4, 2, 3, 1]
> my_slice = slice (0meme 5pm 2)
> > a [my _ slice]
[1, 2, 1] the content of "binary conversion and string conversion in Python" is introduced here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.