Python base data types are converted to each other

Source: Internet
Author: User
Tags string format

strings, numbers, lists, meta-ancestors, dictionaries convert each other

What is the conversion between 1 Int and STR, and what is the result of the transformation? Is there a condition?

     #str (int) can be converted to str  the process has no conditions      #字符串转化为数字必须全部由数字组成      How can I convert between 2  Int  and  bool  by Int (str type), and what is the result of the conversion? Is there a condition?     # int conversion to bool no condition, except 0 conversion to false other numbers are converted to True  bool (number of int)       #int (False) = 0; int (True)  = 1 3 str  and  bool  conversions, What is the result of the conversion? There are no conditions for?     #str   conversion to bool without conditions, NULL string conversion to a Boolean value of false    F non-null to True    bool (SRR type)      #str (true) = ' true '    str (False) = ' flase ' str  and  list  can I convert? How to convert?     #  can  str>>list  1.   2.list (str string) with split cut       #可以  list>>str  1. Using join+  Iteration    2. str (list listing)    example
# ret15 = ' jinxin Alex Wusir '
# ret16 = Ret15.split ()
# Print (ret16)
[' Jinxin ', ' Alex ', ' Wusir ']

# ret15 = ' Jinxin,alex,wusir ' split. (', ') comma string format to make a list of the entire string
# ret16 = Ret15.split (', ')
# Print (ret16)
[' Jinxin ', ' Alex ', ' Wusir ']

# ret15 = ' title Tle tlie '
# ret16 = ret15.split (' t ')
# Print (ret16)
[', ' I ', ' le ', ' le ', ' lie '] What splits that element is deleted as a split point.

Turn the list into a string "' Out is the string
L1 = [' jinxin ', ' Alex ', ' Wusir ']
Li = ". Join (L1)
Print (LI)

Jinxin Alex Wusir
# to False
#0, "", {},[], (), set ()
# # # #字符串与列表互转 # string to list Listl = ' ab_c ' Print (List (' Ab_c '), type (' Ab_c ')) #列表转字符串使用 joinl1 = [' 1 ', ' 2 ', ' 3 ']str = '. Join (l 1) Notice that the string between the strings is empty, so come out is 123print (Str,type (str)) 123li = [' Alex ', ' rain ']temp = '. Join (LI) print (Temp,type (temp)) #元组与列表互转 # tuple to list plus Listtu = (in a.) L = List (TU) print (L,type (l)) l= [1,2,3]# # # list to tuple plus tupleli = [4,5,6]print (Tuple (LI), type (tuple ( LI)))

Python base data types are converted to each other

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.