Basic Python-string, basic python string

Source: Internet
Author: User

Basic Python-string, basic python string
Basic string syntax

Print () Output

In Python 3, strings are Unicode encoded. That is to say, Python strings support multiple languages.

Chr () encoding into characters <----------------------------------->ord()Integer representation of Characters

<---------------------->

Byte Data Representation

   x = b'ABC'

Len () str contains characters

To enable the python file to be read by UTF-8, add two lines at the beginning of the file.

  #!/usr/bin/env python3  # -*- coding: utf-8 -*-

The first line of comment is to tell the Linux/OS X system that this is a Python executable program and will be ignored in Windows;

The second line of comment is to tell the Python interpreter to read the source code according to the UTF-8 encoding, otherwise, the Chinese output you write in the source code may be garbled.

Declaring the UTF-8 code doesn't mean your.pyThe file is UTF-8 encoded and must be ensured that the text editor is using the UTF-8 without BOM encoding:

% String formatting

Similar'Dear xxx, hello! Your phone bill for xx months is xx, and your balance is xx'And so on, and the content of xxx changes according to the variable. Therefore, a simple format method is required.

Here, % is used to format the string.

%sString replacement,%dReplace the value with an integer.

Two % represents a %

 

 

 

 


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.