Python Basic Learning-built-in functions

Source: Internet
Author: User

#!/usr/bin/env python #-*-Coding:utf-8-*-system built-in functions

n =abs ( -1) #绝对值

Print (n)

#bytes () function

S= "Leave"

re= bytes (s,encoding= "utf-8") # bytes () converts a string to bytes

Print (RE)

res = str (re,encoding= "Utf-8") #转换回字符串

Print (res) re= bytes (s,encoding= "gbk") # bytes () converts a string to bytes

Print (RE)

#open函数 file Operation 3-Step open File action file Close file

#打开文件

# R-Read Only

# W Write, first empty the original file, write in

# x-only write if file exists error does not exist create and write content A-append

#以上方式 +b means reading 2 binary data directly

#r + read/write

F=open (' db ', ' W ')

F.write ("Test1,test2,test3,test4")

F.close ()

F=open (' db ', ' a ')

F.write ("/n" + "T1,T2,T3,T4")

F.close ()

F=open (' db ', ' R ')

RD = F.read ()

Rdlist = Rd.split (', ')

F.close ()

Print (rdlist)

F=open (' db ', ' r+ ', encoding= ' utf-8 ')

data = F.read ()

index= F.tell () #取得当前指针的位置 always in bytes 3 bytes of a kanji utf-8

Print (index)

F.seek (3) #把指针调整到 the first position of the parameter position

F.write ("888")

F.close ()

Python Basic Learning-built-in functions

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.