Python Basic 3.5 functions

Source: Internet
Author: User

About the calculated

ABS () #求绝对值

Pow () #求X方, that is, the number of powers

Round () #返回浮点数x的四舍五入值, you can specify the number of decimal places to return

Divmod () #求商和余数 (except floor)

Coerce () #强制转换

>>> coerce (1, 134L)
(1L, 134L)

  

Type conversions

Int ()

Comples ()

Float ()

Long ()

BOOL ()

Binary conversion

Bin ()

Oct ()

Hex ()

ASCII conversion

Ord ()

Chr ()

Mathematical functions

Import Math

Math.sin ()

Math.tan ()

Math.Cos ()

Math.sqrt (X) #X的平方根

Random number function

Import Random

Random.uniform (1,10) #返回1-a floating-point number between 10

Random.range (1,10) #返回一个整数

Random.choice ([i]) #返回其中一个数

Judging function

Isalnum () #判断是否是字母或数字, returns a Boolean value

Isalpha (0 #判断是否为字母

IsDigit () #判断是否为数字

Islower () #判断是否为小写

Isupper () #判断是否为大写

StartsWith () #检查开是子串是否在母串中作为开始, you can specify the start and end bits

EndsWith () #检查开是子串是否在母串中作为结束, you can specify the start and end bits

Isspace () #检测字符串是否只由空格组成

Format functions

Center (N,T)

Ljust (n,t)

Rijust (n,t)

Format () #这个方法会把字符串当作一个模版, formatted with the parameters passed in. The template used for formatting uses curly braces ({,}) as special characters

Search function

Count ()

Find ()

Index ()

RFind ()

Lindex ()

Replace function

Replace (old,new)

Expandtabs (n) #把字符串中的 the tab sign (' \ t ') to a space, the tab symbol (' \ t ') The default number of spaces is 8

Split function

Partition ('. ')

#根据指定的分隔符将字符串进行分割.

#如果字符串包含指定的分隔符,

#则返回一个3元的元组, the first is a substring to the left of the delimiter, the second is the delimiter itself, and the third is the substring to the right of the delimiter

Split ('. ') #通过指定分隔符对字符串进行切片, if the parameter num has a specified value, only the NUM substring is delimited

The Splitlines () #照行 (' \ r ', ' \ r \ n ', \ n ') separates, returns a list containing the rows as elements, if the argument keepends is False, does not contain a newline character, and if true, the newline character is preserved.

Peel function

Strip () #用于移除字符串头尾指定的字符 (default is Space)

Lstrip () #用于截掉字符串左边的空格或指定字符

Rstrip () # #用于截掉字符串右边的空格或指定字符

Python Basic 3.5 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.