python--slices

Source: Internet
Author: User

1. Slices:

>>> s= "Abcdefghi"

>>> S[1:7:2]#隔两个取
' BDF '

>>> s
' Abcdefghi '
>>> S[::-1]
' IHGFEDCBA '
>>> S[-1]
I
>>>

2. #用户输入的形式, output the last letter of each input string

A=raw_input ("Please input a string1:")
B=raw_input ("Please input a string2:")
C=raw_input ("Please input a string3:")
Print A[-1]+b[-1]+c[-1]

Output results

Please input a String1:hello
Please input a String2:python
Please input a string3:mysql
Onl
3. #用户输入三个单词,

#coding =utf-8

Def totalstr ():
S= ""
While 1:
A=raw_input ("Please input a string:")
If a== ".":
Break
Else
S+=A[-1]
Print S
Totalstr ()

4. #在txt文档中写中文的时候惯用写法:

Raw_input ("Please enter a word:". Decode ("Utf-8"). Encode ("GBK") 5. Bit operation:Move right 1 digits to divide the original number size by 2

Move left one means multiply the number size by 2

python--slices

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.