Chr python with the () value into a string, numeric character conversion ord (s) function

1.1 python string definitions

  1.  
    #!/usr/bin/python
  2.  
    # -*- coding: utf8 -*-
  3.  
     
  4.  
    # Definition of a string
  5.  
    s1 = 'this is long String that spans two lines'
  6.  
     
  7.  
    # Indicates the following line is a continuation of the previous line
  8.  
    s2 = 'this is long String\
  9.  
    that spans two lines'
  10.  
     
  11.  
    # Is output as a string
  12.  
    s3 = """this is long String
  13.  
    that spans two lines
  14.  
    """
  15.  
    # Newline character string output
  16.  
    s4 = 'this is long String\n\
  17.  
    that spans two lines'
  18.  
     
  19.  
    print "s1=",s1
  20.  
    print "s2=",s2
  21.  
    print "s3=",s3
  22.  
    print "s4=",s4

 

Output:

  

Conversion between the character and the character value 1.2 python

 A: & characters into numeric value into a string: ord function which can be converted to a string is an integer ranging from [0,65535]

  1.  
    #!/usr/bin/python
  2.  
    # -*- coding: utf8 -*-
  3.  
    # Characters into value
  4.  
    s = 'a'
  5.  
    print ord ( s )
  6.  
    # Value into a string
  7.  
    b = 97
  8.  
    print chr(b)

B: Parameters args chr () function in the [0,256], meaning that only the [0,256] into a string of digital

C: The value is a Unicode code into a Unicode string

  1.  
    #!/usr/bin/python
  2.  
    # -*- coding: utf8 -*-
  3.  
     
  4.  
    # The values ​​were converted to unicode string code
  5.  
    print repr(unichr( 8224))
  6.  
    # Unicode string into the code values
  7.  
    print repr (words ( u '\ u2020' ))

 

D: chr () function and the difference between str function:

           1. chr () function is as a parameter to a small integer, and returns the ASCII character string corresponds to a single character

           2. str () function is to any integer as a parameter and returns the integer a text string

Guess you like

Origin www.cnblogs.com/presleyren/p/11365816.html
Recommended