Python full stack day10 (base data type)

Source: Internet
Author: User

One, the number

1,int converts a string into a number

A = ' 123 '

B=int (a)

B=123

2, convert in binary mode

Num= "a"

>>> num = "a"

>>> Int (num,base=16)

10

  The default base of 10 does not need to be added

3,bit_length is currently the number of bits numbers

>>> age = 3
>>> Age.bit_length ()
2
>>> Age = 8
>>> Age.bit_length ()
4

PS: In Python3, no matter how many numbers are int type

Two, string

1,capitalize First Letter Capital

>>> test= "Zhangsan"
>>> test.capitalize ()
' Zhangsan '

2,casefold,lower the capitalization into lowercase casefold Many unknown correspondence also apply

>>> test= "Zhangsan"

>>> Test.casefold ()

' Zhangsan '

 3,center minimum number of characters, not enough characters to use spaces instead, or you can use other symbols instead of spaces

>>> Test.center (8)

' Zhangsan '
>>> Test.center (9)
' Zhangsan '
>>> Test.center (10)
' Zhangsan '
>>> Test.center (11)
' Zhangsan '

  >>> Test.center (10, ' * ')

' *zhangsan* '

 4,count computes the number of occurrences of a subsequence in a string, and can be represented by a number representing the beginning of the search

  >>> test.count (' Z ')

1

 5,endswith judge whether the end of the door startswith

>>> test.endswith (' a ')

False

>>> test.endswith (' N ')
True

6,find from the beginning, find the location number (starting at 0)

>>> test.find (' H ')

1

>>> test.find (' A ')

2

7,format string is formatted to replace the placeholder in the string with the specified value

>>> test = ' I am {name} '
>>> Test.format (name= ' Zhangsan ')
' I am zhangsan '

  

>>> test = ' I am {0},age={1} '
>>> Test.format (' Zhangsan ', 19)
' I am zhangsan,age=19 '

8,format_map format in dictionary mode

>>> Test
' I am {name} '
>>> Test.format_map ({"Name": "Zhangshan"})
' I am Zhangshan '

9.index function similar to find if it is different from find if no direct error is found

10,isalnum determine if a string contains only letters and numbers

>>> ' ASD '. Isalnum ()
True
>>> ' asd_+ '. Isalnum ()
False

Three, List

Four, Yuan zu

Five, dictionary

VI, Boolean value

Python full stack day10 (base data type)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.